CodeIgniter Forums
File upload with HtmlWebRequest on server [works on localhost] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: File upload with HtmlWebRequest on server [works on localhost] (/showthread.php?tid=79457)



File upload with HtmlWebRequest on server [works on localhost] - MBVape64 - 06-18-2021

Hello,

I have a site where a user records a video of himself, which is directly captured from the camerafeed and then sent via xhr to the backend to be saved.

This works perfectly on localhost (Xampp on windows), but it does not work when I run the exact same code on the server.



XHR code:

Code:
media_recorder.addEventListener('stop', function() {
    // create local object URL from the recorded video blobs
    console.log('recording stopped');
      var f = new FormData();
      f.append('videofile', new Blob(blobs_recorded));
      f.append('renter_id', '<?php echo $rent['id'];?>');
      f.append('type', 'verification');
   
      var xhr=new XMLHttpRequest();

      xhr.open('POST','<?php echo base_url();?>/objects/save_video',false);
      xhr.send(f);
      window.location.replace("<?php echo base_url();?>/objects/verify_renter_done/<?php echo $rent['id'];?>");
      });


Upload code:
PHP Code:
function save_video() 
        {
            $session = \Config\Services::session();
            $code $session->get('code');
            $renter_id $this->request->getPost('renter_id');
            $type $this->request->getPost('type');
            $video $this->request->getFile('videofile');
            
            
//$fileData = file_get_contents($video['tmp_name']);
            $new_name 'verification.webm';
            $filepath FCPATH ."uploads/$code/$renter_id/";
            $video->move($filepath,$new_name);

        

Error:

[Image: 4L4ycTT.png]

PHP Code:
On my development PC (Windows 10with Xampp), the code works fine.
On my live server (Centos8 with apacheit doesnt...

Any help would be greatly appreciated 



RE: File upload with HtmlWebRequest on server [works on localhost] - InsiteFX - 06-18-2021

The error is telling you where the problem is, its not getting the file path check your path.


RE: File upload with HtmlWebRequest on server [works on localhost] - MBVape64 - 06-19-2021

Hello,

Thank you for your reply.

Isn't it saying that the $video object is null though? As in, something goes wrong with the form on the xhr side?

The error log shows an invalid file error...

It does work on localhost, so it seems to be an enviroment problem?


RE: File upload with HtmlWebRequest on server [works on localhost] - MGatner - 06-19-2021

Yes, $video is null because the file upload failed. If it is working in one environment and not another most likely it is an environment restriction - check your max file size upload, upload extension restrictions, memory limit, etc. You should also be able to find the root error in the PHP error logs.


RE: File upload with HtmlWebRequest on server [works on localhost] - MGatner - 06-19-2021

Ooo check that your writable folder is actually writable! Should have put that first.


RE: File upload with HtmlWebRequest on server [works on localhost] - MBVape64 - 06-19-2021

Wasnt the issue.

It was enviromental indeed, php.ini's max upload size was too low for the file I was trying to write.

Thanks for your help!


RE: File upload with HtmlWebRequest on server [works on localhost] - paliz - 06-19-2021

Put your uploads files in public/upload


You can not read file in writable folder


RE: File upload with HtmlWebRequest on server [works on localhost] - ikesela - 06-19-2021

normally on folder permission issue


RE: File upload with HtmlWebRequest on server [works on localhost] - InsiteFX - 06-19-2021

max_upload_size and max_post_size should both be the same value.