php - is_uploaded_file says error but no error code returns -


i have following code:

 if (!is_uploaded_file($_files['sb_file']['tmp_name']))                            {                                echo "error in uploading file <br>".$_files["sb_file"]["error"][$count];                            } 

is_uploaded_file returns false , $_files['sb_file']['errors'] return 0 file not moving in destination folder. how trace error?

foreach ($_files['sb_file']['name'] $filename)         {             //make sure no empty thing goes             if($filename!=""&&$filename!=null)             {                 $temp = explode(".", $filename);                 $extension = end($temp);                 $upload_folder = "/home/content/w/k/1/wk1989/html/".trim($config["upload_folder"]);                  if(!(in_array($extension, $allowedexts)))                     print "$filename has invalid file type <br />";                  else                  {                      $uploaded_file_name = $filename."-".date("ymdhis").".".$extension;                      if ($_files["sb_file"]["error"][$count] > 0)                         {                             echo "<br />error: " . $_files["sb_file"]["error"][$count] . "<br />";                         }                         else                         {                             $target_path = "uploads/";                             $target_path = $target_path.basename( $file_upload['name']);                              print "path = $target_path <br>"; //                            if(move_uploaded_file($file_upload['tmp_name'], $target_path)) { //                            //    echo "the file ".  basename( $file_upload['name']). " has been uploaded"; //                            } else{ //                                //echo "there error uploading file, please try again!"; //                            }                            move_uploaded_file($_files["sb_file"]["tmp_name"][$count],$upload_folder.$uploaded_file_name); //                           if (!is_uploaded_file($_files['sb_file']['tmp_name'][$count])) //                           { //                               echo "error in uploading file <br>".$_files["sb_file"]["error"][$count]; //                           } //                           else //                           { //                                //                           }                            $is_upload = true;                            echo "uploaded = ".$upload_folder.$uploaded_file_name;                          }                         if($is_upload)                         {                             $uploaded_files[] = $upload_folder.$uploaded_file_name;                         }                  }              }              $count++;         } 

first suggest use move_uploaded_file instead of moving file manually. debug current code should print_r($_files) , check if path correct , informations file delivered script.

i found post function is_uploaded_file handles filename case-sensitive (even on windows) (read original post).

i think best way handling uploaded file somethink this:

$upload_dir = "d:/user_uploads/"; foreach($_files $key => $file_arr) {   switch($file_arr["error"])   {     case upload_err_ok:     {       if($file_arr["size"]>0)       {          $result = move_uploaded_file($file_arr["tmp_name"], $upload_dir.$file_arr["name"]);         if($result === true) echo "upload ok";         else                 echo "upload failed";       }       else echo "the file has no content";     }     default:      {       echo "upload error #".$file_arr["error"]." field" . $key;       print_r($files_arr); // debuging, remove on live systems     }   } } 

if need, can add more case-blocks e.g. upload_err_form_size. , on unix/linix or ntfs drives should check if upload_dir is_writeable().


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -