使用PHP将视频上传到服务器 [英] Uploading video to server using PHP

查看:43
本文介绍了使用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";
     }
    ?>

推荐答案

如果你的文件很大,

两个 PHP 配置选项控制最大上传大小:upload_max_filesizepost_max_size.对于 10 兆字节的文件大小,两者都可以设置为10M".

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.

但是,您还需要考虑完成上传所需的时间.PHP 脚本通常会在 30 秒后超时,但在健康的宽带连接上上传 10MB 文件至少需要 3 分钟(请记住,上传速度通常比下载速度慢 5 倍).此外,操作或保存上传的图像也可能导致脚本超时.因此,我们需要将 PHP 的 max_input_time 和 max_execution_time 设置为 300(以秒为单位指定的 5 分钟)

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)

在 .htaccess 中添加此代码,

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

或者您可以使用 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);

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

这篇关于使用PHP将视频上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆