drumhrd Posted August 30, 2009 Share Posted August 30, 2009 Sorry guys I am sure this is simple..but simple minds can't get it right apparently. I am attempting a file upload. But testing after $_POST['submit'] it is showing $_FILES being empty. /etc/php5/apache2/php.ini showing file_uploads = On node the print_r($_FILES); showing Array ( ) everytime <?php if($_POST['submit']) { $blacklist = array(".php", ".phtml", ".php3", ".php4", ".php5"); print_r($_FILES); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['userfile'])) { echo "We do not allow uploading PHP files\n"; exit; } } $imageinfo = getimagesize($_FILES['userfile']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/png') { echo "Sorry, we only accept GIF and JPEG images\n"; exit; } $uploaddir = '/var/www/web-file-server/band_images/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "File uploading failed.\n"; } } else { ?> <form name="submit" action="<?php echo $SCRIPT_NAME ?>" method="POST" enctype="multipart/form-data"> Select the file to upload: <input type="file" name="userfile"> <input type="submit" name="submit" value="upload"> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2009 Share Posted August 31, 2009 Since the $_POST array does have something in it but the $_FILES array does not, it is likely that uploads are not enabled on your server. What does a phpinfo(); statement show for the file_uploads setting? Quote Link to comment Share on other sites More sharing options...
drumhrd Posted September 1, 2009 Author Share Posted September 1, 2009 phpinfo(); showing file uploads on. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2009 Share Posted September 2, 2009 The code you posted works on a system where uploads are enabled (except that $SCRIPT_NAME will only exist on some old out of date php configurations) and if you were exceeding any of php's upload size limits the symptoms would be different. What does adding the following three lines of code immediately after the first opening <?php tag show after you submit the form? ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
drumhrd Posted September 2, 2009 Author Share Posted September 2, 2009 ok so I change my code a bit.. $_FILES['userfile'] is supposed to be $_FILES['userfile']['tmp_name'] in the getimagesize, preg_match, and move_uploaded_file functions I added the error checking code so now my script is as follows <?php ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); if($_POST['submit']) { $blacklist = array(".php", ".phtml", ".php3", ".php4", ".php5"); print_r($_FILES); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['userfile']['tmp_name'])) { echo "We do not allow uploading PHP files\n"; exit; } } $imageinfo = getimagesize($_FILES['userfile']['tmp_name']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/png') { echo "Sorry, we only accept GIF and JPEG images\n"; exit; } $uploaddir = '/var/www/web-file-server/band_images/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['tmp_name']); echo $uploadfile; if (move_uploaded_file($_FILES['userfile'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "<br />File uploading failed.\n"; } } else { ?> <form name="submit" action="https://www.artists2you.com/s/upload.php" method="POST" enctype="multipart/form-data"> Select the file to upload: <input type="file" name="userfile"> <input type="submit" name="submit" value="upload"> </form> <? } ?> now I am getting the following output from the browsers Array ( [userfile] => Array ( [name] => bottom-bar.gif [type] => image/gif [tmp_name] => /tmp/phpKJwnWE [error] => 0 => 283 ) ) /var/www/web-file-server/band_images/phpKJwnWE Notice: Array to string conversion in /var/www/s/upload.php on line 34 File uploading failed. the move_uploaded_file functions appears to not be working. went through and chmod 777 web-file-server/band_images. phpinfo() showing file_uploads = on I dunno..I am stuck. please help!! Quote Link to comment Share on other sites More sharing options...
drumhrd Posted September 2, 2009 Author Share Posted September 2, 2009 I found the issue. thanks for the help if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) kinda helps to specify the field inside the array inside the array Quote Link to comment 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.