chriscloyd Posted December 9, 2008 Share Posted December 9, 2008 this is my script might be long but all of it works until it gets to the new part where it uploads it wont up load it says folder is not set to 777 but it is i did set it <?php session_start(); $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); $max_filesize = 524288; $upload_path = '/myphotos'; $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. echo "Checking Theres A Photo: "; ob_start(); for($i=1;$i<11;$i++) { echo $i.' '; if ($i == 10) { if ($filename != NULL) { $_SESSION['cpcerror'] = 0; echo '✔'; } else { $_SESSION['cpcerror'] = 1; echo '✖'; } } ob_flush(); flush(); usleep(500000); ob_end_flush(); } if ($_SESSION['cpcerror'] == 0) { unset($_SESSION['cpcerror']); echo '<br>Checking Photo Type: '; ob_start(); for($i=1;$i<11;$i++) { echo $i.' '; if ($i == 10) { if(in_array($ext,$allowed_filetypes)) { $_SESSION['cpcerror'] = 0; echo '✔'; } else { $_SESSION['cpcerror'] = 1; echo '✖'; } } ob_flush(); flush(); usleep(500000); ob_end_flush(); } } if ($_SESSION['cpcerror'] == 0) { unset($_SESSION['cpcerror']); echo '<br>Checking Photo Size: '; ob_start(); for($i=1;$i<11;$i++) { echo $i.' '; if ($i == 10) { if(filesize($_FILES['userfile']['tmp_name']) < $max_filesize) { $_SESSION['cpcerror'] = 0; echo '✔'; } else { $_SESSION['cpcerror'] = 1; echo '✖'; } } ob_flush(); flush(); usleep(500000); ob_end_flush(); } } if ($_SESSION['cpcerror'] == 0) { unset($_SESSION['cpcerror']); echo '<br>Generating New File Name: '; ob_start(); for($i=1;$i<11;$i++) { echo $i.' '; if ($i == 10) { $random = rand(5768,983468); $new_name = $random.'_'.$filename; echo '✔'; $_SESSION['cpcerror'] = 0; } ob_flush(); flush(); usleep(500000); ob_end_flush(); } } if ($_SESSION['cpcerror'] == 0) { unset($_SESSION['cpcerror']); echo '<br>Uploading Photo To <a href="../index.php?p=photos">My Photos</a>: '; ob_start(); for($i=1;$i<11;$i++) { echo $i.' '; if ($i == 10) { if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path.'/'.$new_name)) { echo '✔'; } else { if(!is_writable($upload_path)) { echo 'You cannot upload to the specified directory, please CHMOD it to 777.'; } echo '✖'; } } ob_flush(); flush(); usleep(500000); ob_end_flush(); } } if ($_SESSION['cpcerror'] == 1) { echo 'Could No Upload File Try Again'; header("Location: index.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2008 Share Posted December 9, 2008 There are many reasons why a move_uploaded_file() statement will fail, not just a permissions problem. Add the following two lines immediately after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710257 Share on other sites More sharing options...
chriscloyd Posted December 9, 2008 Author Share Posted December 9, 2008 Checking Theres A Photo: 1 2 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 3 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 4 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 5 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 6 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 7 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 8 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 9 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 10 ✔ Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26 Checking Photo Type: 1 2 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 3 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 4 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 5 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 6 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 7 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 8 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 9 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 10 ✔ Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46 Checking Photo Size: 1 2 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 3 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 4 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 5 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 6 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 7 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 8 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 9 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 10 ✔ Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67 Uploading Photo To My Photos: 1 2 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 3 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 4 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 5 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 6 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 7 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 8 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 9 Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 10 You cannot upload to the specified directory, please CHMOD it to 777.✖ Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86 Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89 Notice: Undefined index: cpcerror in /home/cpc/public_html/admin/upload_photo.php on line 93 Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710260 Share on other sites More sharing options...
chriscloyd Posted December 9, 2008 Author Share Posted December 9, 2008 nothing about uploadin file Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710261 Share on other sites More sharing options...
chriscloyd Posted December 9, 2008 Author Share Posted December 9, 2008 here u can test it ur self http://chriscloydblog.com/admin/test.php Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710262 Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2008 Share Posted December 9, 2008 'Generating New File Name: ' is not showing as well. I believe that all the usage of output buffering is dropping output, including relevant errors. Start with the basics and get it to work first, without all the BS of looping 1...10 and the output buffering. The entire script probably executes in a few 100 milliseconds and doing all that might look neat but is probably covering up what is really happening. Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710287 Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2008 Share Posted December 9, 2008 If you actually try your current online code, you get the following - Warning: move_uploaded_file(/myphotos/somefile.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/cpc/public_html/admin/upload_photo.php on line 77 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpc6OYJp' to '/myphotos/somefile.jpg' in Your posted code in this thread is not your actual code because the Generating New File Name:/$new_name logic is not present in the actual code. I'm not going to guess why the code you have been trying has not output the above two errors. Those two error messages mean that the folder /myphotos does not exist in the root of the hard disk, which is why the is_writable() is returning a FALSE value as well. If the myphotos folder is actually within your web document root folder, then you need to form the path correctly. A leading slash / on a file system path refers to the root of the hard disk not your document root. Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710293 Share on other sites More sharing options...
chriscloyd Posted December 9, 2008 Author Share Posted December 9, 2008 did it normal like this <?php // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); $max_filesize = 524288; $upload_path = 'myphotos/'; $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. else echo 'There was an error during the file upload. Please try again.'; ?> and got this error There was an error during the file upload. Please try again. Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710296 Share on other sites More sharing options...
chriscloyd Posted December 9, 2008 Author Share Posted December 9, 2008 and yes i coded this because i made my own code and it was in there generating a new one it was $random = rand(5689,983498); $newname = $random.'_'.$_FILE['userfile']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710297 Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2008 Share Posted December 9, 2008 The way to find out why it is failing has already been mentioned - http://www.phpfreaks.com/forums/index.php/topic,229168.msg1059852.html#msg1059852 Quote Link to comment https://forums.phpfreaks.com/topic/136173-solved-file-upload/#findComment-710357 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.