Welcome Guest, Not a member yet? Register   Sign In
File upload with HtmlWebRequest on server [works on localhost]
#1

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 
Reply
#2

(This post was last modified: 06-19-2021, 12:52 AM by InsiteFX. Edit Reason: Spelling Error )

The error is telling you where the problem is, its not getting the file path check your path.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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?
Reply
#4

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.
Reply
#5

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

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!
Reply
#7

Put your uploads files in public/upload


You can not read file in writable folder
Enlightenment  Is  Freedom
Reply
#8

normally on folder permission issue
Reply
#9

max_upload_size and max_post_size should both be the same value.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB