Verot class.upload.php 上传大文件

Posted

技术标签:

【中文标题】Verot class.upload.php 上传大文件【英文标题】:Verot class.upload.php uploading big files 【发布时间】: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 />';
        

     

【问题讨论】:

可能是一些事情。如果您在自己的机器上并且对任何系统文件进行了更改,那么您之后是否重新启动了所有服务?或者,如果您尝试将图像存储为 BLOB,那么它可能太小,请尝试 MEDIUMBLOB 或 LONGBLOB。看看使用php.net/manual/en/function.error-reporting.php 和php.net/manual/en/function.mysql-error.php 是否有任何结果 【参考方案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 仍然是相关的

以上是关于Verot class.upload.php 上传大文件的主要内容,如果未能解决你的问题,请参考以下文章

论坛遇到附件上传失败问题总结(discuz)

使用 class.upload 上传 php 图片

需要了解 PHP 类 [关闭]

文件上传漏洞原理是啥?

.netcore上传文件是单个上传还是批量

什么是文件上传漏洞