Jump to content

[SOLVED] Uploading Problem


SkyRanger

Recommended Posts

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>";
}

Link to comment
Share on other sites

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?    ???

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.