ukweb Posted October 10, 2007 Share Posted October 10, 2007 Hi. I've got the following code to upload an image file, and when you upload to a single location (without the 'thumb' upload it works fine, but as I want the image to be uploaded twice, it won't work. it fails at the point of checking whether the thumbs directory is writable, and it definitely is but it fails! Can anyone help at all?? THe code is below! THanks! // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); $max_filesize = 524288; $upload_path = 'user_files/uploaded/images/uploaded/'; $upload_thumb_path = $upload_path.'thumbs/'; $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); if(!is_writable($uploa_thumbd_path)) die('You cannot upload to the specified directory thumb, please CHMOD it to 777.'); if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_thumb_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/ Share on other sites More sharing options...
freakstyle Posted October 10, 2007 Share Posted October 10, 2007 you have a spelling error: $upload_thumb_path = $upload_path.'thumbs/'; if(!is_writable($uploa_thumbd_path)) //change to: $upload_thumb_path = $upload_path.'thumbs/'; if(!is_writable($upload_thumb_path)) good luck Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/#findComment-366225 Share on other sites More sharing options...
ukweb Posted October 10, 2007 Author Share Posted October 10, 2007 Right, I've corrected the spelling and now it isn't bringing up an error for the path not being writable, however, the main image is uploading but the 'thumb' one isn't its just returning the error. I can't see why. // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); $max_filesize = 524288; $upload_path = 'user_files/uploaded/images/uploaded/'; $upload_thumb_path = $upload_path.'thumbs/'; $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); if(!is_writable($upload_thumb_path)) die('You cannot upload to the specified directory thumb, please CHMOD it to 777.'); if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_thumb_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/#findComment-366554 Share on other sites More sharing options...
ukweb Posted October 10, 2007 Author Share Posted October 10, 2007 I've got it working now by using the following code! Thanks for everyone's help! // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); $max_filesize = 524288; $upload_path = 'user_files/uploaded/images/uploaded/'; $upload_thumb_path = $upload_path.'thumbs/'; $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. if(copy($upload_path.$filename, $upload_thumb_path.$filename)) echo 'Thumbnail created successfully'.$filename; else echo 'Thumbnail hit a wall!'; } else echo 'There was an error during the file upload. Please try again.'; // It failed . Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/#findComment-366585 Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 solved plz!? Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/#findComment-366586 Share on other sites More sharing options...
ukweb Posted October 10, 2007 Author Share Posted October 10, 2007 Hi, I had already marked it as solved, guess you viewed it jus b4 I hit the solved button, as the email telling me the topic had been replied to (basically when you posted on it) had "SOLVED" in the subject line! Thanks for your help, I can go to bed now and not worry about any more PHP til the morning (I'm in the UK, its 00:34 here!!) Nite all! Quote Link to comment https://forums.phpfreaks.com/topic/72632-solved-image-upload-not-working/#findComment-366592 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.