SkyRanger Posted May 26, 2007 Share Posted May 26, 2007 I'm not sure what is going on, so far I can get all the extensions except for mp3 so far, haven't tested the other audio files yet. The error I am getting is: File 1: Not selected. Here is the code I am using: Sorry for all the code but I can't figure out what the problem is $upload_dir = "files/uploads/"; //number of files to upload. $num_files = 1; //the file size in bytes. $size_bytes =100000000; //51200 bytes = 50KB. //Extensions you want files uploaded limited to. $limitedext = array(".gif",".jpg",".jpeg",".png",".txt",".pdf",".doc",".rtf",".fdr",".mp3",".wav",".mid",".m3u"); //check if the directory exists or not. if (!is_dir("$upload_dir")) { die ("Error: The directory <b>($upload_dir)</b> doesn\'t exist"); } //check if the directory is writable. if (!is_writeable("$upload_dir")){ die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)"); } //if the form has been submitted, then do the upload process //infact, if you clicked on (Upload Now!) button. if (isset($_POST['upload_form'])){ echo "<h3>Upload results:</h3>"; //do a loop for uploading files based on ($num_files) number of files. for ($i = 1; $i <= $num_files; $i++) { //define variables to hold the values. $new_file = $_FILES['file'.$i]; $file_name = $new_file['name']; //to remove spaces from file name we have to replace it with \"_\". $file_name = str_replace(' ', '_', $file_name); $file_tmp = $new_file['tmp_name']; $file_size = $new_file['size']; #-----------------------------------------------------------# # this code will check if the files was selected or not. # #-----------------------------------------------------------# if (!is_uploaded_file($file_tmp)) { //print error message and file number. echo "File $i: Not selected.<br>"; }else{ #-----------------------------------------------------------# # this code will check file extension # #-----------------------------------------------------------# $ext = strrchr($file_name,'.'); if (!in_array(strtolower($ext),$limitedext)) { echo "File $i: ($file_name) Wrong file extension. <br>"; }else{ #-----------------------------------------------------------# # this code will check file size is correct # #-----------------------------------------------------------# if ($file_size > $size_bytes){ echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>"; }else{ #-----------------------------------------------------------# # this code check if file is Already EXISTS. # #-----------------------------------------------------------# if(file_exists($upload_dir.$file_name)){ echo "File $i: ($file_name) already exists.<br>"; }else{ #-----------------------------------------------------------# # this function will upload the files. cool # #-----------------------------------------------------------# if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) { $uploaddate = date("F j, Y"); $filename = $file_name; $owner = $logged; include "inc/dbinfo.inc.php"; // database connect script. $connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbname"); $sql = "INSERT INTO memberimages VALUES ('', '".$filename."', '".$owner."', '".$desc."', '".$uploaddate."', '".$sect."')"; $result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error()); echo "<script type=\"text/javascript\"> <!-- window.location = \"membersfiles.php\" //--> </script>"; }else{ echo "File: Faild to upload.<br>"; }#end of (move_uploaded_file). }#end of (file_exists). }#end of (file_size). }#end of (limitedext). }#end of (!is_uploaded_file). }#end of (for loop). # print back button. echo "»<a href=\"membersfiles.php\">back</a>"; //////////////////////////////////////////////////////////////////////////////// //else if the form didn\'t submitted then show it. }else{ echo " <form method=\"post\" action=\"membersfiles.php\" enctype=\"multipart/form-data\">"; echo "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"80\"><div class=\"forumtext\" align=\"right\">Section: </div></td> <td width=\"320\"><select class=\"textbox\" name=\"sect\" size=\"1\" id=\"sect\"> <option value=\"works\">Completed Works</option> <option value=\"progress\">In Progress</option> <option value=\"images\">Members Photos</option> <option value=\"misc\">Misc Files</option> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td valign=\"top\"><div class=\"forumtext\" align=\"right\">Description: </div></td> <td><textarea name=\"desc\" cols=\"30\" rows=\"3\"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div class=\"forumtext\" align=\"right\">File: </div></td> <td>"; // show the file input field based on($num_files). for ($i = 1; $i <= $num_files; $i++) { echo "<input size=\"36\" class=\"textbox\" type=\"file\" name=\"file". $i ."\">"; } echo "</td> </tr> <tr> <td> </td> <td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><input type=\"submit\" name=\"upload_form\" class=\"formbutton\" value=\"Upload Now!\"></td> </tr> </table> </form>"; } Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/ Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262069 Share on other sites More sharing options...
taith Posted May 26, 2007 Share Posted May 26, 2007 try changing echo "File $i: Not selected.<br>"; to echo "File $file_tmp: Not selected.<br>"; might give ya a more... helpful error... lol Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262072 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 No nothing Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262082 Share on other sites More sharing options...
taith Posted May 26, 2007 Share Posted May 26, 2007 then theres your problem... $file_tmp = $new_file['tmp_name']; doesnt exist... therefore, empty, therefore, !is_uploaded_file(). Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262086 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 I have tested every extension but for some strange reason the only extension that is not working is mp3 Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262088 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262123 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262176 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 Echo taith. Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262181 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 Yeah, I know, but can't seen to find the problem there, as I mentioned, I tried uploading files with all of the other extensions and the only one that fails is the mp3 Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262183 Share on other sites More sharing options...
taith Posted May 26, 2007 Share Posted May 26, 2007 echo me!?!??! well... my first guess... would be that the filesize is too big on the mp3, causing the html to not upload it, therefore it wouldnt register it as an uploaded file... Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262184 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 I uped the file size to 8 mb = 8388608 bytes, tried uploading a 4 mb mp3 file and still getting same error: File 1: Not selected Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262204 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262231 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 Ok, now I am totally confused. I just tried another upload script i found off the net to see if it is my coding, and what do I see, the same darn error as my code. For some reason the mp3 file disappears when I upload it which give me the error of: No File selected. Does anybody have a clue what and or why this could be happening? ??? Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262241 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 instead of bumping over and over.. just create a very simple test script and then add to it until the problem occures, then work from their.. heres a quick test one to try <?php echo "debug<br />POST"; print_r($_POST); echo "<br />Files"; print_r($_FILES); echo "<br />end debug"; ?> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="1024000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <?php if(isset($_POST['submit'])) { set_time_limit(); $target_path = "uploads/"; $name = $_FILES['uploadedfile']['name']; $tmpname = $_FILES['uploadedfile']['tmp_name']; $target_path = $target_path.$name; if(move_uploaded_file($tmpname, $target_path)) { echo "The file $name has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } die; ?> heres an output debug POSTArray ( [MAX_FILE_SIZE] => 1024 ) FilesArray ( [uploadedfile] => Array ( [name] => marvin.mp3 [type] => [tmp_name] => [error] => 2 => 0 ) ) end debug Oh it failed "[error] => 2" but with [MAX_FILE_SIZE] => 1024, so i increased that to 1024000, try again and. debug POSTArray ( [MAX_FILE_SIZE] => 1024000 ) FilesArray ( [uploadedfile] => Array ( [name] => marvin.mp3 [type] => audio/mpeg [tmp_name] => /tmp/phpmH5mHW [error] => 0 => 606336 ) ) end debug Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262250 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 Thanks MadTechie, just tried that script and here is what I got: debug POSTArray ( [MAX_FILE_SIZE] => 8388608 ) FilesArray ( [uploadedfile] => Array ( [name] => music.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ) ) end debug Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262266 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 error type 1 The uploaded file exceeds the upload_max_filesize directive in php.ini. Now we know the reason it fails.. maybe try <?php ini_set("upload_max_filesize", 10000000); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262270 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 ok,not sure if I did this right: <?php ini_set("upload_max_filesize", 8388608); echo "debug<br />POST"; print_r($_POST); echo "<br />Files"; print_r($_FILES); echo "<br />end debug"; ?> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="8388608" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <?php if(isset($_POST['submit'])) { set_time_limit(); $target_path = "files/"; $name = $_FILES['uploadedfile']['name']; $tmpname = $_FILES['uploadedfile']['tmp_name']; $target_path = $target_path.$name; if(move_uploaded_file($tmpname, $target_path)) { echo "The file $name has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } die; ?> I still get: debug POSTArray ( [MAX_FILE_SIZE] => 8388608 ) FilesArray ( [uploadedfile] => Array ( [name] => music.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ) ) end debug Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262272 Share on other sites More sharing options...
SkyRanger Posted May 26, 2007 Author Share Posted May 26, 2007 Speaking to my server admin, he is pushing the upload limit to 8 meg so hopefully that should fix any problems. Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262275 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 looks OK but i would increase it to more, as the value is measured in bytes, also 'post_max_size' must be taken into account take a look at data handling Edit: sounds good Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262277 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 echo me!?!??! well... my first guess... would be that the filesize is too big on the mp3, causing the html to not upload it, therefore it wouldnt register it as an uploaded file... Well done taith Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262282 Share on other sites More sharing options...
SkyRanger Posted May 27, 2007 Author Share Posted May 27, 2007 Yes well done taith, and to you too MadTechie, if you hadn't mentioned the php.ini then I wouldn't have realized the the upload limit was set to 2M, I changed it to 8 to cover any future problems with other files. Quote Link to comment https://forums.phpfreaks.com/topic/53024-solved-uploading-problem/#findComment-262394 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.