简体   繁体   English

用php上传大文件后出现“无此文件”错误

[英]`No such file` error after uploading large files with php

There is a service for uploading large files (more than 500MB) with php/apache. 有一项使用php / apache上传大文件(超过500MB)的服务。 The progress of upload is tracked by the uploadprogress pecl extension. 上载进度由上载uploadprogress pecl扩展跟踪。 This scheme works fine only for small file uploads. 此方案仅适用于小文件上传。

However, there is a problem when uploading large files. 但是,上传大文件时存在问题。 Once the upload is finished, there is a standard information in the $_FILES array showing there are no errors. 上传完成后,$ _FILES数组中将显示一个标准信息,表明没有错误。 The problem is that the /tmp/phpXXXX file itself doesn't exist by this time. 问题是/ tmp / phpXXXX文件本身目前尚不存在。

I've tested that if we manually remove the tmp file during the upload, upload process will not stop and the error will be raised only after the upload is finished. 我已经测试过,如果我们在上传过程中手动删除tmp文件,则上传过程不会停止,并且仅在上传完成后才会引发错误。

Hosting provider says that there are no maintenance scripts that are removing tmp files. 托管服务提供商说,没有维护脚本正在删除tmp文件。 Also it says that such tmp files are available in the filesystem almost until the end of the upload, and then they disappear. 它还说,此类tmp文件几乎可以在文件系统中使用,直到上载结束为止,然后它们消失。

Could it be caused by the apache/server/php configuration? 可能是由apache / server / php配置引起的吗? Is there anything in the OS that may affect these tmp files? 操作系统中是否有任何可能影响这些tmp文件的内容?

OS is Ubuntu 8 LTS 操作系统是Ubuntu 8 LTS

Any help would be appreciated! 任何帮助,将不胜感激!

There is a number of reasons why uploaded files might not work. 有多种原因可能导致上传的文件无法正常工作。

  • upload_max_filesize 的upload_max_filesize
  • post_max_size - needs to be larger than upload_max_filesize post_max_size-必须大于upload_max_filesize
$POST_MAX_SIZE = ini_get('post_max_size');
    $unit = strtoupper(substr($POST_MAX_SIZE, -1));
    $multiplier = ($unit == 'M' ? 1048576
        : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));

    if (isset($_SERVER['CONTENT_LENGTH'])) {
        if ((int) $_SERVER['CONTENT_LENGTH'] > $multiplier * (int) 
          $POST_MAX_SIZE && $POST_MAX_SIZE) {
            $error = 'POST exceeded maximum allowed size.';
        }
    }
  • $_FILES['myfile']['error'] > 0 (see: http://php.net/manual/en/features.file-upload.errors.php ) $_FILES['myfile']['error'] > 0(请参阅: http : //php.net/manual/zh/features.file-upload.errors.php
  • File has no name / filename too long (value of $_FILES['myfile']['name'] ) 文件没有名称/文件名太长( $_FILES['myfile']['name']
  • Trying to read a non-multipart upload, using multipart functions (EG move_uploaded_file / is_uploaded_file returns false) 尝试使用分段功能读取非分段上传(例如,EG move_uploaded_file / is_uploaded_file返回false)
  • upload_tmp_dir not writeable (this is /tmp by default in linux) upload_tmp_dir不可写(在Linux中默认为/ tmp)
  • Destination not writeable !is_writable($targetDir) 目标不可写!is_writable($targetDir)
  • Disk full (although this usually gives UPLOAD_ERR_CANT_WRITE error) 磁盘已满(尽管通常会出现UPLOAD_ERR_CANT_WRITE错误)

Have you checked your server LimitRequestBody parameter ? 您是否检查了服务器LimitRequestBody参数? It may not be high enough for the files you're trying to upload. 您尝试上传的文件可能不够高。

Have you verified your php upload_max_filesize and post_max_size settings? 您是否验证了您的php upload_max_filesize和post_max_size设置? (in your php.ini file) (在您的php.ini文件中)

Once the upload is finished, there is a standard information in the $_FILES array showing there are no errors. 上传完成后,$ _FILES数组中将显示一个标准信息,表明没有错误。

I'm assuming you checked the error element? 我假设您检查了error元素? It's an integer that corresponds to one of the upload error constants , such as UPLOAD_ERR_INI_SIZE . 这是一个整数,对应于一个上传错误常量 ,例如UPLOAD_ERR_INI_SIZE

As I understand it, UPLOAD_ERR_NO_FILE can also be returned if the file size goes over the PHP post_max_size or some Apache limit (Arkh mentioned LimitRequestBody ) 据我了解,如果文件大小超过PHP post_max_size或某些Apache限制(Arkh提到LimitRequestBody ),也可以返回UPLOAD_ERR_NO_FILE

Side Note: Ubuntu 10.04 LTS is out now 旁注:Ubuntu 10.04 LTS现已发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM