Mutley Posted January 15, 2009 Share Posted January 15, 2009 Hi guys, Having an issue with uploading an image, it doesn't seem to upload it, so when it goes to resize them, it can't find it. Can anyone see why it might no be uploading in this code: <?php if($_POST['action'] == 'add_product'){ //Product Variables $cat_id = $_POST['cat_id']; $product_name = $_POST['product_name']; //main image $product_image[0] = $_FILES['product_image0']; //closeup images $product_image[1] = $_FILES['product_image1']; $product_image[2] = $_FILES['product_image2']; $product_image[3] = $_FILES['product_image3']; $product_image[4] = $_FILES['product_image4']; $product_image[5] = $_FILES['product_image5']; $product_image[6] = $_FILES['product_image6']; $product_image[7] = $_FILES['product_image7']; $product_image[8] = $_FILES['product_image8']; $product_description = $_POST['product_description']; //Image Types $AllowedImages = array('image/jpeg','image/pjpeg'); //Preverification of image filetypes for ($i=0; $i<count($product_image); $i++){ if (in_array($product_image[$i]['type'], $AllowedImages)){ $product_image_allowed = 1; //current image type is allowed } else { $product_image_allowed = 0; //current image type is not allowed break; //found an image type that's denied - quit the loop } } //Verification if(!empty($cat_id) && !empty($product_name) && !empty($product_description) && $product_image['error'] == 0 && $product_image_allowed == 1){ //Continue & Add to DB //process the images for ($i=0; $i<count($product_image); $i++){ $product_image_name[$i] = md5(microtime()).'.jpg'; //generate the filename //Write Original File WriteFile($cfg['productimages']['original']['folder'].$product_image_name[$i], file_get_contents($product_image[$i]['tmp_name'])); //Create medium sized thumbnail $ImageFunctions->Open($cfg['productimages']['original']['folder'].$product_image_name[$i]); $ImageFunctions->Resize(245,184); $ImageFunctions->RawOutput(); WriteFile($cfg['productimages']['medium']['folder'].$product_image_name[$i], $ImageFunctions->Output['Content']); //Get Dimensions $Image[$i]['medium']['width'] = $ImageFunctions->Width; $Image[$i]['medium']['height'] = $ImageFunctions->Height; //Create smaill sized thumbnail $ImageFunctions->Open($cfg['productimages']['original']['folder'].$product_image_name[$i]); $ImageFunctions->Resize(65,49); $ImageFunctions->RawOutput(); WriteFile($cfg['productimages']['small']['folder'].$product_image_name[$i], $ImageFunctions->Output['Content']); //Get Dimensions $Image[$i]['small']['width'] = $ImageFunctions->Width; $Image[$i]['small']['height'] = $ImageFunctions->Height; //End Image Processing } ?> Error: Warning: fopen(/home/sfengine/public_html/sfengine/sfengineering.ie/productimages/original/dbe59b51badf7b3d61c00538abc8f0c6.jpg) [function.fopen]: failed to open stream: No such file or directory in /home/sfengine/public_html/admin/includes/global.inc.php on line 68 Warning: fwrite(): supplied argument is not a valid stream resource in /home/sfengine/public_html/admin/includes/global.inc.php on line 69 Warning: fclose(): supplied argument is not a valid stream resource in /home/sfengine/public_html/admin/includes/global.inc.php on line 70 Unable to open the file: /home/sfengine/public_html/sfengine/sfengineering.ie/productimages/original/dbe59b51badf7b3d61c00538abc8f0c6.jpg global.inc.php: <?php //Product Image Locations $cfg['productimages']['small']['folder'] = '/home/sfengine/public_html/sfengineering.ie/productimages/small/'; $cfg['productimages']['medium']['folder'] = '/home/sfengine/public_html/sfengine/sfengineering.ie/productimages/medium/'; $cfg['productimages']['original']['folder'] = '/home/sfengine/public_html/sfengine/sfengineering.ie/productimages/original/'; $cfg['productimages']['small']['url'] = 'http://sfengineering.ie/productimages/small/'; $cfg['productimages']['medium']['url'] = 'http://sfengineering.ie/productimages/medium/'; $cfg['productimages']['original']['url'] = 'http://sfengineering.ie/productimages/original/'; $cfg['basefolder'] = '/home/sfengine/public_html/sfengine/sfengineering.ie/'; ?> Thanks in advance, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/ Share on other sites More sharing options...
Mutley Posted January 15, 2009 Author Share Posted January 15, 2009 Any ideas? ??? Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737874 Share on other sites More sharing options...
phparray Posted January 15, 2009 Share Posted January 15, 2009 The problem is most likely one of 2 things permissions on the upload folder or a missing enctype on the form. Without the seeing the form I can't tell you if it's wrong but you'll want to make sure you have enctype="multipart/form-data" in the opening form tag. As for permissions the upload folder needs to be writable for the user your script is running as. Depending on the server environment php could be running as apache,nobody, or a particular user. You should be checking to make sure the file was uploaded before attempting to re-size it. is_uploaded_file works great for that. http://us3.php.net/manual/en/function.is-uploaded-file.php My last thought which should have been my first is that make sure the php.ini file allows uploads. file_uploads should be On in the php.ini file and safe_mode Off. Dave Arnold, Training Specialist, [email protected] http://www.HostMySite.com?utm_source=bb Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737902 Share on other sites More sharing options...
Mutley Posted January 15, 2009 Author Share Posted January 15, 2009 Thanks for your reply! The form is correct and the folders are set to CHMOD 777, the PHP.ini is okay too... it seems it doesn't upload the file to begin with, hence the error, when I look for it on the server, it isn't there either. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737908 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2009 Share Posted January 15, 2009 It would take seeing all the code in global.inc.php to help, specifically what function contains the line with the error. My guess is that you have the source/destination files mixed up. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737918 Share on other sites More sharing options...
Mutley Posted January 15, 2009 Author Share Posted January 15, 2009 The function is: <?php //Write File function WriteFile($File, $Data){ $handle = fopen($File, 'w'); fwrite($handle, $Data); fclose($handle); } ?> Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737921 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2009 Share Posted January 15, 2009 Do you actually have a folder with that exact spelling and capitalization - /home/sfengine/public_html/sfengine/sfengineering.ie/productimages/original/ it seems it doesn't upload the file to begin with, hence the error, when I look for it on the server, it isn't there either.If that statement means you cannot see the ['tmp_name'] uploaded file, that is because you would need to be very fast as it is destroyed when the form processing code ends. If you had a permissions problem, the error would indicate so. If file_get_contents($product_image[$i]['tmp_name']) was failing because the tmp_name file does not exist, the error would indicate so. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737939 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2009 Share Posted January 15, 2009 And based on what your "small" folder path is and what the url paths are, I would guess that the "medium" and "original" paths are incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-737949 Share on other sites More sharing options...
phparray Posted January 16, 2009 Share Posted January 16, 2009 The best thing to do is validate each step in the process to verify where the break down is happening. Once you find the problem fixing it will be easy. Test the value of $product_image[$i]['error']. If it is equal to 0 move on else use die() to kill the script and output its value. Just before calling WriteFile() enter: #test for errors before writing file if($product_image[$i]['error'] != 0) die('Error on Upload: '. $product_image[$i]['error']); Might want to make it a little nicer for production but this will do the trick. Use http://us.php.net/manual/en/features.file-upload.errors.php to determine the problem based on the error number. This should be include with all file upload scripts. It makes like easier when things like this pop up. Dave Arnold, Training Specialist, [email protected] http://www.HostMySite.com?utm_source=bb Quote Link to comment https://forums.phpfreaks.com/topic/140974-solved-image-upload-error-cant-find-image/#findComment-738106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.