大型文件的PHP文件上传错误 [英] PHP file upload error for large files

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

问题描述

我正在尝试使用本地服务器上的php上传文件并将其保存在当前工作目录中.对于小于2mb的任何文件类型,该代码都可以正常工作,但超过此大小会出现错误.我还修改了php.ini文件中的上传和发布大小,但这没有帮助.它给出了4个错误:

I am trying to upload files using php on my local server and save it in the current working directory.The code is working fine for any file type of size less than 2mb but above this size it gives error. I have also modified the upload and post size in php.ini file,but it was of no help.It gives 4 errors:

  1. 未定义索引:第3行的C:\ wamp64 \ www \ project \ upload.php中的温度

  1. Undefined index: temp in C:\wamp64\www\project\upload.php on line 3

file_get_contents(C:\ wamp64 \ www \ project \ project):无法打开流:C:\ wamp64 \ www \ project \ upload.php中没有此类文件或目录在第5行

file_get_contents(C:\wamp64\www\project\project): failed to open stream: No such file or directory in C:\wamp64\www\project\upload.php on line 5

未定义索引:第6行的C:\ wamp64 \ www \ project \ upload.php中的温度

Undefined index: temp in C:\wamp64\www\project\upload.php on line 6

未定义的索引:第18行的C:\ wamp64 \ www \ project \ upload.php中的温度

Undefined index: temp in C:\wamp64\www\project\upload.php on line 18

最后显示抱歉,上传您的文件时出错."

At end it shows "Sorry, there was an error uploading your file.".

我将上传的文件保存在upload.php所在的位置.

I am saving the uploaded file in the same location where upload.php is located.

Upload.php:

<?php
$target_dir = getcwd();
$target_file = $target_dir .'\project'. basename($_FILES["temp"]["name"]);
$uploadOk = 1;
echo file_get_contents($target_file);
if ($_FILES["temp"]["size"] > 5000000000) 
{
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}

if ($uploadOk == 0) 
{
    echo "Sorry, your file was not uploaded.";
} 
else 
{
    if (move_uploaded_file($_FILES["temp"]["tmp_name"], $target_file)) 
    {
        echo "The file ". basename( $_FILES["temp"]["name"]). " has been 
uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>

推荐答案

在您的 php.ini 文件中查找这两个参数,WAMPServer附带了

Look at your php.ini file for these 2 parameters, WAMPServer comes configured with

upload_max_filesize = 2M
post_max_size = 8M

upload_max_filesize 增大到要允许卸载的最大文件.如果打算一次上传多个文件,则更大.

Increase the upload_max_filesize to a little bigger that the largest file you want to allow to be unloaded. Or a lot larger if you intend to upload more than one file at a time.

然后将 post_max_size 增加到您将 upload_max_filesize 设置为这样的较大数字

Then increase post_max_size to a number LARGER that you set upload_max_filesize to so for example

upload_max_filesize = 80M
post_max_size = 85M

当文件在POST缓冲区以及表格中可能存在的所有其他字段中传输时,

post_max_size 必须大于 upload_max_filesize

post_max_size must be larger that upload_max_filesize as the file is transported in the POST buffer as well as all other fields that may exist on your form

请注意使用wampmanager图标编辑 php.ini ,这将确保您编辑正确的 php.ini 有2个.

NOTE use the wampmanager icon to get to edit php.ini and that will ensure you edit the correct php.ini there are 2.

wampmanager -> php -> php.ini

还请记住,一旦编辑并保存了 php.ini

wampmanager -> Apache -> Service administration 'wampapache' -> Restart Service

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

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