Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/Apache Upload Failure

Status
Not open for further replies.

Pisail

IS-IT--Management
Jul 3, 2001
5
US
We have PHP 4.04 installed on a server running Red Hat 7.0 and have run into a problem that spans multiple scripts. Image/Photo uploads cannot be done. PHP passes info to mysql fine, and PHP/mysql programs run just fine, except for the issue of uploading files through PHP. We have tried installing several scripts that call for image upload through a PHP admin (postcards, gallery type scripts etc) and in each case the upload fails to occur. No error messages, no log files, just empty space. We've eliminated mysql as a source problem since text is written to the database and at least one of the PHP scripts does not write the image to mysql but rather to a directory. Anyone experience anything similar or can anyone offer any thoughts. We've checked all the usual, and are just stumped.
 
$valid_image_file_types = array("jpg" => "image/jpg",
"gif" => "image/gif",
"png" => "image/png"
);

$max_file_size = 20480;

/* is filesize < 1? */
if($image_file_size == 0) {
$error = 1;
$image_file_error = &quot;You chose to upload an image, but the file you chose has no size!<br>\n&quot;;
}
/* file can not be larger than 20 KB */
if($image_file_size > $max_file_size) {
$error = 1;
$image_file_error = &quot;The image you chose to upload is too large! (must be 20KB or less)<br>\n&quot;;
}
/* is the type of image being uploaded valid */
if(!in_array($image_file_type,$valid_image_file_types)) {
$error = 1;
$image_file_error = &quot;The image you are uploading is not a gif, jpg, or png<br>\n&quot;;
}

/* is the size of the image valid */
$image_info = getimagesize($image_file);

if(($image_info[0] > 100)||($image_info[1] > 100)) {
$error = 1;
$image_file_error = &quot;The image is larger than 100x100 pixels.<br>\n&quot;;
}

if($error) {
die($image_file_error);
}
else {
// perform you inserts, updates, or whatever else here
}


This has worked for me in my aplications without any glitches.

Not only do we store these images in databases, but in some apps we store them within our filesystem.

Hope this helps,
Chad.
 
Thanks, Chad. The code is certainly worth hanging on to for future use, as well as comparing to program code to isolate problems. It still doesn't help me much in my specific problem, because the problem doesn't seem to be in the scripts since it spans several scripts. Still, I'll take the code and throw it in a script and see if it works. Anything to rule out possible causes.
 
Pisail,

Have you ensured that your field-type is BLOB? If you are storing binary data in your database, BLOB is what you should be using.

I have never had any problems either storing my files in databases or within the file-system.

If this still does not help, please explain in more detail exactly what errors/problems you are experiencing. You stated that not only would the files upload and store in MySQL, but would not successfully save within the location you specify in your filesystem. The solution I gave above should be successful within the context of your problem as stated above.

Chad.
 
Inlandpac,
I was re-reading my original post, and noticed right way I wasn't real clear ;) Php/Mysql works fine with any text based upload. The problem with uploading only occurs with images/graphics, wether to database or file. Our efforts thus far have centered on config checks of every possible sort. So far no luck. I'll have the tech that's working with it more closely post tomorrow after we try the script you posted. I'm pretty sure it's not script specific since we have tried several scripts with the same result. I do want to try your script however since you have had no problems with it and it's pretty straightforward. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top