【问题标题】:Verot class.upload.php uploading big filesVerot class.upload.php 上传大文件
【发布时间】:2016-05-07 18:56:52
【问题描述】:

我使用上传表单上传图片。

case 'png':
                        if (!function_exists('imagecreatefrompng')) {
                            $this->processed = false;
                            $this->error = $this->translate('no_create_support', array('PNG'));
                        } else {
                            echo $this->file_src_pathname;
                            echo $this->log;
                            echo $this->error;
                            echo $image_src = @imagecreatefrompng($this->file_src_pathname);
                            if (!$image_src) {
                                $this->processed = false;
                                $this->error = $this->translate('create_error', array('PNG'));
                            } else {
                                $this->log .= '- source image is PNG<br />';
                            }
                        }
                        break;

@imagecreatefrompng($this->file_src_pathname) 函数是我的代码中断的那段代码。它不会在该代码之后输出任何内容,除非我将其注释掉。我已经将内存限制更改为 256M 并将文件上传更改为 64M。文件名已设置。我不知道为什么它只在处理大文件时才破坏我的代码。大家有什么想法吗?

文件上传页面的代码是:

//表单处理

include('../includes/class.upload.php');

    $files = array();
foreach ($_FILES['my_field'] as $k => $l) {
    foreach ($l as $i => $v) {
        if (!array_key_exists($i, $files)) 
            $files[$i] = array();
        $files[$i][$k] = $v;
    }
}

foreach ($files as $file) {
if(!empty($file)){

$handle = new Upload($file, 'nl_NL');

            if (!file_exists("../classified_images/$adid")) 
    mkdir("../classified_images/$adid", 0777); 

        $tag_code_p = generatePassword(25);

        if ($handle->uploaded) {
        $oriname = $handle->file_src_name;
        $handle->mime_magic_check = true;
        $handle->allowed = array('image/*');
        $handle->image_convert = 'jpg';
        $newname = $adid."_big_".$tag_code_p;
        $handle->file_new_name_body   = $newname;
        $handle->image_resize          = true;          
        $handle->image_ratio_fill      = true;
        $handle->image_y               = 600;
        $handle->image_x               = 800;
        $handle->image_background_color = '#FFFFFF';

// // 现在,我们开始上传“进程”。也就是复制上传的文件 // // 从它的临时位置到想要的位置 // // 可能类似于 $handle->Process('/home/www/my_uploads/'); $handle->Process("../classified_images/");

        // we check if everything went OK
        if ($handle->processed) {

        $handle->image_convert = 'jpg';
        $newnamesmall =$adid."_small_".$tag_code_p;
        $handle->file_new_name_body   = $newnamesmall;
        $handle->image_resize          = true;          
        $handle->image_ratio_fill      = true;
        $handle->image_y               = 94;
        $handle->image_x               = 125;
        $handle->image_background_color = '#FFFFFF';

        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');
        $handle->Process("../classified_images/");

        $handle->clean();
                //inserten in database
    $sql_foto_insert = "insert into  photos 
                ( adid,  photosmall,  photo)
                values
                ('$adid', '$newnamesmall.jpg','$newname.jpg')";
    $foto_result = mysql_query($sql_foto_insert);  

            // everything was fine !
            //$msg .= $oriname.' '.LANG_FOTOS_SAVED.'<br />';
            $allok = 1;

        } else {
            // one error occured
            $msg .= $handle->error . '<br />';
        }

    } 

【问题讨论】:

标签: php file-upload filesize


【解决方案1】:

这可能是由配置问题引起的。由于文件>特定大小会发生这种情况,我觉得它可能与 php ini 设置有关。

在您的 php ini 设置中检查 upload_max_filesizepost_max_size。这些可以设置为 4MB。您可以增加这些值以使其正常工作。

如果您处于无法编辑 php ini 的共享主机环境中,您可以将它们添加到 .htaccess 文件中,如下所示:

php_value upload_max_filesize 7M
php_value post_max_size 7M

您还应该从函数中删除@ 以查看错误是什么。在开发/调试时通过添加@ 来抑制错误是一个坏主意。

此外,如果您在本地机器或自己的开发服务器中,请打开 apache error_log 并检查最后几行以查看错误所在。如果您在第三方服务器上,大多数控制面板都提供了查看错误日志的界面。

【讨论】:

  • OP 声明:“我已将内存限制更改为 256M,文件上传为 64M。”
  • @Fred-ii- post_max_size 仍然是相关的
猜你喜欢
  • 2019-10-07
  • 2014-06-07
  • 2016-03-22
  • 1970-01-01
  • 2013-09-13
  • 2015-09-13
  • 2011-12-04
  • 2011-01-27
相关资源
最近更新 更多