使用PHP上传大文件高达100MB [英] Upload large File upto 100MB using php

查看:447
本文介绍了使用PHP上传大文件高达100MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



项目几乎完成,但上传模块无法正常工作。当我尝试上传一个大小为kb的文件时,脚本就执行了以及上传文件,但是当我选择一个大于1MB的文件,它会在上传过程中给出错误信息,任何人都可以帮助我如何在PHP中使用HTTP协议上传文件。



这是我的上传脚本:

  //配置 - 您的选项

$ 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('你试图上传的文件是不允许的。
if(filesize($ _ FILES ['userfile'] ['tmp_name'])> $ max_filesize)
die('您尝试上传的文件太大。
if(!is_writable($ upload_path))
die('您不能上传到指定的目录,请将其改为777.');
if(move_uploaded_file($ _ FILES ['userfile'] ['tmp_name'],$ upload_path。$ filename))
echo'您的文件上传成功,查看文件< a href =' 。$ upload_path。$ filename。'title =Your File> here< / a>';
else
echo'上传时出错。


解决方案

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



post_max_size
upload_max_filesize


I am making a file hosting website like web hosting sites (megaupload, rapidshare, mediafire etc.) using PHP (or tell me if its easy to implement in ASP.NET).

Project is almost complete but uploading module is not working correctly. I Google it but couldn't find any help so thought to ask here if anybody can help.

Whenever I try to upload a file of size in kb, the script execute well and upload file but when I select a file of size greater than 1MB, it gives error message during upload, can anybody help me how can I upload file using HTTP protocols in PHP.

Here is my script for upload:

// 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.';  

解决方案

open php.ini, find and edit directives:

post_max_size upload_max_filesize

这篇关于使用PHP上传大文件高达100MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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