使用php上传大文件高达100MB

时间:2011-01-21 09:12:38

标签: php html http file-upload

我正在使用PHP制作一个托管网站的文件,例如网站托管网站(megaupload,rapidshare,mediafire等)(或告诉我它是否易于在ASP.NET中实现)。

项目已基本完成,但上传模块无法正常运行。我谷歌它但找不到任何帮助,所以想在这里询问是否有人可以提供帮助。

每当我尝试上传大小为kb的文件时,脚本执行良好并上传文件但是当我选择大小超过1MB的文件时,它会在上传过程中出现错误信息,有人可以帮我如何上传文件在PHP中使用HTTP协议。

这是我的上传脚本:

// Configuration - Your Options

$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); 
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
 if(!in_array($ext,$allowed_filetypes))
 die('The file you attempted to upload is not allowed.');
 if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
  die('The file you attempted to upload is too large.');
 if(!is_writable($upload_path))
  die('You cannot upload to the specified directory, please CHMOD it to 777.');
 if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
     echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; 
 else
     echo 'Error during uploading.';  

3 个答案:

答案 0 :(得分:3)

打开php.ini,查找并编辑指令:

的post_max_size 的upload_max_filesize

答案 1 :(得分:3)

以下是一些以前的堆栈溢出问题,可能有您正在寻找的答案 https://stackoverflow.com/questions/4083100/php-uploading-large-files-fai

upload large files using php, apache

这是一个有一些好建议的外部网站 http://www.radinks.com/upload/config.php

如果用户也从您的网站下载大文件,您可能希望指示您的网络服务器提供压缩下载。你如何做到这一点取决于你的网络服务器,并意识到它可能会对使用IE6等旧浏览器的人产生负面影响。

答案 2 :(得分:1)

ini_set("memory_limit","2048M");    # 2 GB
set_time_limit(0);          # unlimited transfer time