2

I written custom module to upload bulk import of products with error report.
Here is the code I am using to move CSV file to particular location.
I am getting error always saying that

"Uploaded file doesn't exist.File not moved"

My code as follows. Please correct me if I am wrong:

 $file = $this->getRequest()->getFiles('product_custom');  
        //print_r($file);exit;
        $file_name = $file["name"];    
        $ext = pathinfo($file_name, PATHINFO_EXTENSION);  
          $org_target_path = $this->_dir->getPath('pub')."/uploads/".$vendorId."/original/";
         if (!is_dir($org_target_path)) { mkdir($org_target_path , 0777, true); }        

            $base_filename =  pathinfo($file_name, PATHINFO_FILENAME);

            $ext = pathinfo($file_name, PATHINFO_EXTENSION); // get the extension of the file
            //$org_newname = $base_filename."_original.".$ext;
            $org_target = $org_target_path.$file_name;

          //  $newname="./videos/".$video_name;
            $orig = isset($_FILES['product_custom']) && isset($_FILES['product_custom']['tmp_name']) ? $_FILES['product_custom']['tmp_name'] : '';
            if (empty($orig)) {
              echo "Uploaded file doesn't exist.";
            }
            $copied = move_uploaded_file($orig, $org_target);
            // Optional
            if ($copied) {
              echo "File moved.";
            }
            else {
              echo "File not moved.";
            }
  • Use echo "<pre>"; print_r($_FILES); echo "</pre>"; die; and check what response you are getting, by doing this you can debug the value of your $_FILE array – Shoaib Munir Mar 13 at 12:46
  • Array ( [product_custom] => Array ( [name] => Women_Sarees_a9pvOFeTHfOTgczh_1552479602.csv [type] => text/csv [tmp_name] => /tmp/phpmp6blc [error] => 0 [size] => 4009 ) ) got this response – Dinesh Mar 13 at 12:51
  • That really confusing, +1 on your question – Shoaib Munir Mar 13 at 12:55
  • What if you change empty to isset? – BartZalas Mar 13 at 13:05
  • yes it worked for me , I changed to isset. – Dinesh Mar 15 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.