Codeigniter : mp4 video won't upload, no error

2019-02-21 01:57发布

问题:

I'm creating a form to upload video file, but I have a strange error.

My form is like this:

<div style="color : red;"><?php echo $error;?></div>    
<?php echo form_open_multipart('data_center/ajout_ressource/formulaire_video'); ?>
   //various input text fields...

   <input type="file" name="video">
   <input type="submit" value="Ajouter cette ressource" />
</form>±

My method to get upload is (it's inside something to check if the rest of the form is ok):

  $dir = './assets/video/';
  $config['upload_path'] = $dir;
  $config['allowed_types'] = 'avi|flv|wmv|mpeg|mp3|mp4';
  $config['max_size']   = '102400';
  $this->load->library('upload',$config);
  if ( ! $this->upload->do_upload('video')){
     $error = array('error' => $this->upload->display_errors());
     $this->load->view('data_center/ajout_video', $error);
  } else {
     redirect('data_center/data_center/','refresh');
  }

Concerning mime types, I think it's ok:

'mp4'   =>      'video/mp4',
'wmv'   =>     array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'),
'flv'   =>     array('video/flv', 'video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
'avi'   =>  'video/x-msvideo',

When I try to upload a mp4 file it automatically redirect me (although I'm not sure it's a redirection) to the form, unfilled and no error message, even if I comment the lines in case of upload failure not to load the view again or if the rest of the form is uncorrect (it should not attempt to upload the video and load the form pre-filled).

Whereas for example, if I put the wrong type of file, I can see the error message ('The filetype you are attempting to upload is not allowed' for example), or if the form is wrong I can see the error of the form.

Finally, I must add that I modified php.ini to authorize such big files, and that I did pretty much the same thing with a form for pictures (jpg,jpeg,png...) which works perfectly but also redirect me to an unfilled form if I try to upload a .mp4 file.

Edit: I just downloaded an flv video to try, and it uploaded perfectly fine, but its size was less than 8mb (default config), and a 40mb flv file had the same problem as the mp4 file, although I changed my config in php.ini for 100mb

回答1:

Efectively you have to change two parameters in PHP ini file

post_max_size = 100M
upload_max_filesize = 100M

But you may also want to change the apache abuse protection parameter (100M)

LimitRequestBody 1073741824

And by another hand, PHP have a time limit too of 30 sec per script, so your script will die at 30 seconds of running.

You may also want to increase the time to be sure your script does not die meanwhile you are uploading, copying etc,

set_time_limit(600);  // 10 minutos execution