Ali Imran
Ali Imran

Reputation: 23

Uploading video to server using PHP

I have video which i want to upload to server the same code i am using for audio file that is uploading but when i upload a video file it does not upload

      <?php
      $uploaddir = 'pro/';
      $file = basename($_FILES['userfile']['name']);
      $uploadfile = $uploaddir . $file;

      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      echo "OK";
     } 
     else {
     echo "ERROR";
     }
    ?>

Upvotes: 1

Views: 7073

Answers (2)

Prasanth Bendra
Prasanth Bendra

Reputation: 32710

If your files are big,

Two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size. Both can be set to, say, “10M” for 10 megabyte file sizes.

However, you also need to consider the time it takes to complete an upload. PHP scripts normally time-out after 30 seconds, but a 10MB file would take at least 3 minutes to upload on a healthy broadband connection (remember that upload speeds are typically five times slower than download speeds). In addition, manipulating or saving an uploaded image may also cause script time-outs. We therefore need to set PHP’s max_input_time and max_execution_time to something like 300 (5 minutes specified in seconds)

In .htaccess add this code,

php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300

Or you can make the settings in your php page itself using ini_set

ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);

Ref: http://www.sitepoint.com/upload-large-files-in-php/

Upvotes: 2

Hdhams
Hdhams

Reputation: 24

You can also check the answer stackoverflow.com/questions/14076929/php-image-upload-script where file size should be specified. Its may be default filesize Issue.

  <?php
  $uploaddir = 'pro/';
      $max_filesize = 10485760;
     //you should specify the value you want to be maximum of video.

    if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
   die('The file you attempted to upload is too large.');

     $file = basename($_FILES['userfile']['name']);
      $uploadfile = $uploaddir . $file;

      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      echo "OK";
     } 
     else {
     echo "ERROR";
     }
  ?>

Upvotes: 1

Related Questions