草庐IT

php - 由于大小无法上传文件

coder 2024-04-08 原文

我正在尝试使用 PHP 上传文件!我试过上传 PNG、JPG、PDF、TXT 文件,这些上传仅在文件大小为 20kb 左右时有效。 当我尝试上传大小约为 150KB 的文件时,它会打印 $_FILE error = 3 并且文件名可以说是“1234.png”,其中 tmp_name 是空的,图像本身也是如此!这是我的代码

ini_set('display_errors',1);
error_reporting(-1);

$imageTmp = addslashes($_FILES['image']['tmp_name']);
//$imageTmp = $_FILES['image']['tmp_name'];
$imageOldName = addslashes($_FILES['image']['name']);
$imageData = file_get_contents($imageTmp);
//$imageData = base64_encode($imageTmp);

echo 'image temp name: '. $imageTmp .' ';
echo 'error: '. $_FILES['image']['error']. ' ';
echo 'image name: '. $imageOldName. ' ';
echo 'image data: '. $imageData. ' ';
echo 'image type:'. $_FILES['image']['type'];
echo "<pre>";
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";


$inipath = php_ini_loaded_file();

if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}

我尝试了多种解决方案,例如更改 post_max_size = 200Mupload_max_filesize = 200M 的值而不是 32M

这是尝试上传 4KB 的 txt 文件的结果:

image temp name: /Applications/MAMP/tmp/php/phpOc7d6a error: 0 
image Name: test.txt image data: hello image type:text/plain
POST:Array
(
[submit] => Record Test
)
FILES:Array
(
[image] => Array
    (
        [name] => test.txt
        [type] => text/plain
        [tmp_name] => /Applications/MAMP/tmp/php/phpOc7d6a
        [error] => 0
        [size] => 405
    )

  )  
  Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini

上传PNG文件127KB的结果:

Warning: file_get_contents(): Filename cannot be empty in path/test1.php on line 10 image temp name: error: 3 image name: IMG_8807.JPG image data: image type:

POST:Array
(
)
FILES:Array
(
[image] => Array
    (
        [name] => IMG_8807.JPG
        [type] => 
        [tmp_name] => 
        [error] => 3
        [size] => 0
    )

)
Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini

顺便说一句,上传失败后,服务器崩溃并显示 502 网关,我必须重新启动 Apache!

最佳答案

正如 php 文档所说:

UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data. 
A possibly cause for this is that the upload was cancelled by the user (pressed ESC, etc).

也许:

  • 权限错误

  • 服务器上没有足够的可用空间。

  • 从 iOS 上传。

  • 由于浏览器限制,上传文件夹时可能会发生此错误。发生在 Mac OS X 上。

这些是您可以尝试的一些事情。希望这会有所帮助。

关于php - 由于大小无法上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315978/

有关php - 由于大小无法上传文件的更多相关文章

  1. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  2. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  3. ruby-on-rails - 在 Rails 中将文件大小字符串转换为等效千字节 - 2

    我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,

  4. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  5. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  6. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  7. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  8. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  9. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  10. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

随机推荐