Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
File Upload NAme Trouble
Old 04-26-2004, 04:15 AM File Upload NAme Trouble
I R PHP's Avatar
Average Talker

Posts: 18
Location: ATL
Trades: 0

Hi, I am working on a project that involves uploading files to a directory on the server and saving the name of the file in a mysql table. Then this info is read and displayed to the browser. Well as long as the name of the files does not contain spaces it works fine, but if it does, everything behind the first space is truncated. The file name is correct in the table and the directory which leads me to believe that the problem is in how the name is read from mysql. Does anyone know of a command that will allow me to read through the spaces in the file name?

URl to project: www.ahome4rent.net.
I R PHP is offline
Reply With Quote
View Public Profile Visit I R PHP's homepage!
 
 
Register now for full access!
Old 04-26-2004, 11:24 AM
Skilled Talker

Posts: 75
Location: New Jersey, USA
Trades: 0
I doubt it's a mysql issue. If it's stored in the DB correctly, then you are prolly doing a SELECT by hand to make that determination. Which means, It's most likely somewhere after you read from the DB. Try looking at the raw HTML source, which may give you a hint. Try hardcoding a select which you know ahead of time what the result should be.
__________________

Please login or register to view this content. Registration is FREE

Where you can get personal, online!
eBlush_Hector is offline
Reply With Quote
View Public Profile Visit eBlush_Hector's homepage!
 
Old 04-26-2004, 01:07 PM
I R PHP's Avatar
Average Talker

Posts: 18
Location: ATL
Trades: 0

I looked at the html and nothing obvious shows. Everything looks good. Here is the Code that deals with the Uploaded files. Maybe there is something in it that I missed. I ususally work through the issue, but this one has me baffled!

**********************************************
Upload Code:

//Start file upload script
$u = 0;

foreach($HTTP_POST_FILES as $file_name => $file_array){
if (empty($file_array['name'])){
$load .="";
}else{ //If there is a file
$load .="<br>\n";
$load .="Name:".$file_array['name']."<br>\n";
$load .="Type:".$file_array['type']."<br>\n";
$load .="Size:".$file_array['size']." bytes<br>\n\n";


$name = $file_array['name'];

}



//Test to make sure that uploaded file is of proper format and copy to specified directory if true.
if (is_uploaded_file( $file_array['tmp_name']) && ( $file_array['type'] == "image/pjpeg"
|| $file_array['type'] == "image/gif"
|| $file_array['type'] == "image/x-png"
|| $file_array['type'] == "application/x-shockwave-flash"
|| $file_array['type'] == "video/avi"
|| $file_array['type'] == "video/quicktime"
|| $file_array['type'] == "image/bmp")){
move_uploaded_file($file_array['tmp_name'], "$file_dir/$name") or die("Could not copy file");
}
$photo[$u] = $file_array['name'];
//print $photo[$u];
$u++; //Increment the counter.
**********************************************
Write to database Section

//Query the database and insert values.
$sql3 = "INSERT INTO prop
(memb, webs, add1, city, st, zip, bdrm, bath, cnty, cost, dep, avbl, term, desrpt, drtns, disclaim, amty, school, photo1, photo2, photo3, photo4, photo5, photo6, fpln, type)
VALUES ('$usr_id','$webs','$add1','$city','$st', '$zip','$bdrm','$bath','$cnty','$cost','$dep','$av bl', '$term', '$desrpt', '$drtns', '$disclaim', '$amtys', '$schools', '$photo1', '$photo2', '$photo3', '$photo4','$photo5', '$photo6', '$fpln', '$type')";
$rs3 = mysql_query($sql3, $dbh)
or die(mysql_error());
$pass_id = mysql_insert_id();
}
***********************************************
Write to Directory section

$the_file = $directory.$img_name;
$last_file = file($the_file);

//Change to appropriate left section.
if($bnft or $investor or $hs_srch){
$content .= '&nbsp;';
}elseif(!$bnft or !$investor or!$hs_srch){
$content .= '
<div align="center"><img src='.$the_file.' alt="pic_1"></div><br>
<div align="center"><a href="#" target="_top">Additional Photos</a> <a href="#" target="_top">Floor Plan</a> <a href="#" target="_top">Virtual Tour</a></div>
<br>
<div align="center" class="pic_num">Property '.$num.' of '.$prop_num.'</div><br>
';
}


closedir($dp);
***********************************************

I have spaces in the names of other values in the tables and they work well. It's only the name of the uploaded file that gives me trouble!
I R PHP is offline
Reply With Quote
View Public Profile Visit I R PHP's homepage!
 
Old 04-26-2004, 01:31 PM
Skilled Talker

Posts: 75
Location: New Jersey, USA
Trades: 0
-You verified that the name, with spaces, is properly stored in the DB?
-You verified that it returns properly IMMEDIATELY after the DB read, by printing it <b>filename</b> without doing anything else to it?
-You verified that the select you're using in the code executes as expected outside the code, by querying from the MySQL client?

Litter your code with prints until you see where it breaks. Also, is there any reason you're using the supplied name and not your own pic ID, of sorts? It would seem to me, that using the client supplied name can create all sorts of filenaming problems, from legal characters to upper and lowercase.

Let us know what you find!
Thanks
__________________

Please login or register to view this content. Registration is FREE

Where you can get personal, online!
eBlush_Hector is offline
Reply With Quote
View Public Profile Visit eBlush_Hector's homepage!
 
Old 04-26-2004, 04:08 PM Revised Code!
I R PHP's Avatar
Average Talker

Posts: 18
Location: ATL
Trades: 0
I still didn't find anything wrong so I took your advise and created my own names for the files and it works great. It cost me a few extra steps though, but it works!
Thanks! I appreciate the help!

Here is the revision:
**********************************************
//Start file upload script
---------I moved this up to execute first without the files-----
//Query the database and insert values.
$sql3 = "INSERT INTO prop (memb, webs, add1, city, st, zip, bdrm, bath, cnty, cost, dep, avbl, term, desrpt, drtns, disclaim, amty, school, type) VALUES ('$usr_id','$webs','$add1','$city','$st', '$zip','$bdrm','$bath','$cnty','$cost','$dep','$av bl', '$term', '$desrpt', '$drtns', '$disclaim', '$amtys', '$schools','$type')";
$rs3 = mysql_query($sql3, $dbh) or die(mysql_error());
-------I returned the id of the new row to add to the name of each file-------
$pass_id = mysql_insert_id();
print $pass_id;
$u = 0;

foreach($HTTP_POST_FILES as $file_name => $file_array){
if (empty($file_array['name'])){
$load .="";
}else{ //If there is a file
$load .="<br>\n";
$load .="Name:".$file_array['name']."<br>\n";
$load .="Type:".$file_array['type']."<br>\n";
$load .="Size:".$file_array['size']." bytes<br>\n\n";
}
------I add the proper extension to the file name--------
$Ua = $u +1;
//Add the correct extension to the file name.
if($file_array['type'] == "image/pjpeg"){
$name = $pass_id."_photo".$Ua.".jpg";
}elseif($file_array['type'] == "image/gif"){
$name = $pass_id."_photo".$Ua.".gif";
}elseif($file_array['type'] == "image/x-png"){
$name = $pass_id."_photo".$Ua.".png";
}elseif($file_array['type'] == "image/bmp"){
$name = $pass_id."_photo".$Ua.".bmp";
}elseif($file_array['type'] == "application/x-shockwave-flash"){
$name = $pass_id."_photo".$Ua.".swf";
}elseif($file_array['type'] == "video/quicktime"){
$name = $pass_id."_photo".$Ua.".mov";
}else{
$name = "";

}

print "$name";
*********************************************
//Test to make sure that uploaded file is of proper format and copy to specified directory if true.
if (is_uploaded_file( $file_array['tmp_name']) && ( $file_array['type'] == "image/pjpeg" || $file_array['type'] == "image/gif"
|| $file_array['type'] == "image/x-png" || $file_array['type'] == "application/x-shockwave-flash" || $file_array['type'] == "video/quicktime"
|| $file_array['type'] == "image/bmp")){
move_uploaded_file($file_array['tmp_name'], "$file_dir/$name") or die("Could not copy file");
}

if(!empty($name)){
$photo[$u] = $name;
}else{
$photo[$u] = "No Photo Available!";
}

//print $photo[$u];
$u++; //Increment the counter.


}
$photo1= $photo[0];
$photo2= $photo[1];
$photo3= $photo[2];
$photo4= $photo[3];
$photo5= $photo[4];
$photo6= $photo[5];
$fpln= $photo[6];

---Now I Update the row with the renamed images-----
//Query the database and insert values.
$sql3a = "UPDATE prop SET photo1 ='$photo1', photo2 ='$photo2', photo3 ='$photo3', photo4 ='$photo4', photo5 ='$photo5', photo6 ='$photo6', fpln ='$fpln' WHERE id = '$pass_id'";
$rs3a = mysql_query($sql3a, $dbh) or die(mysql_error());

Last edited by I R PHP; 04-26-2004 at 04:12 PM..
I R PHP is offline
Reply With Quote
View Public Profile Visit I R PHP's homepage!
 
Old 04-26-2004, 04:19 PM
Skilled Talker

Posts: 75
Location: New Jersey, USA
Trades: 0
You're welcome! Believe me, and I'm sure many here will agree, you're much better off taking control of the filename.

Thanks for letting us know you're issue is solved.
__________________

Please login or register to view this content. Registration is FREE

Where you can get personal, online!
eBlush_Hector is offline
Reply With Quote
View Public Profile Visit eBlush_Hector's homepage!
 
Old 06-14-2007, 01:43 PM Re: File Upload NAme Trouble
Skilled Talker

Latest Blog Post:
My book update
Posts: 97
Name: Eric
Location: Las Vegas
Trades: 0
I agree, People put some crazy characters in their file names. I always rename files and usually count how many files are in the directory and add that to the end so you'll never have a duplicate
__________________

Please login or register to view this content. Registration is FREE

Eric - M
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
peanutpad is offline
Reply With Quote
View Public Profile Visit peanutpad's homepage!
 
Reply     « Reply to File Upload NAme Trouble
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23278 seconds with 12 queries