move_uploaded_file 不起作用,没有错误

2023-11-23

我正在运行一个脚本,该脚本移动上传的文件move_uploaded_file()。我已经这样做了数千次,但由于某种原因它不起作用。我已确认以下事项:

  1. <form> using method="post"并纠正enctype
  2. 从表单引用的正确文件
  3. 目录有权限777
  4. all the memory_limit, max_execution_time等设置为超高设置以避免超时

基本上,下面的脚本仅返回Your image is too big.。我还启用了显示所有错误,但仍然没有收到错误。有任何想法吗?

$time = time();
$target_path = "/absolute/path/to/temp/directory/temp/";

$target_path = $target_path.$time.'.jpg'; 

if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {            

} else{
        $error .= '<li>Your image is too big.</li>';
}

使用 1and1 托管和 php.ini hack :P

UPDATE 1

我想补充一点,脚本的响应恰好在 60 秒后发生。

UPDATE 2

我们可能会在这方面有所进展。只是print_r($_FILES)这是数组的结果:

Array ( 
    [image] => Array ( 
        [name] => P2120267.JPG 
        [type] => 
        [tmp_name] => 
        [error] => 1 
        [size] => 0 
    ) 
) 

所以这让我相信文件没有正确上传到服务器或其他什么?我已经查过了,邮寄表格是<form action="" method="post" enctype="multipart/form-data">。那么,据我所知,文件没有上传到服务器的临时区域?

UPDATE 3

注意到了[error] => 1在上面的数组中。这显然取决于文件大小大于upload_max_filesize。但是,当我将其设置为128M,60 秒后出现白屏死机。我上传的文件大小为 2.5MB

这是我的 php.ini 文件:

register_globals=off
memory_limit = 128M 
max_execution_time=3600 
post_max_size = 128M
upload_max_filesize= 128M 

UPDATE 4

根据上述详细信息,我似乎收到了 WSOD,但图像正在上传。那么,如何停止WSOD呢?我在任何地方都找不到任何相关的错误。

更新 5 - 找到了!

我为没有给你们提供所有代码而感到羞耻。看起来与这一行有关:

resizeImage($feedBurnerStatsSource, PHOTOMSGDIR.'temp/'.$time.'-tmp.jpg',$width,$height);

在下面的代码中:

function resizeImage($source, $destination = NULL,$wdt, $height = NULL){
    if(empty($height)){
            // Height is nit set so we are keeping the same aspect ratio.
            list($width, $height) = getimagesize($source);
            if($width > $height){
                    $w = $wdt;
                    $h = ($height / $width) * $w;
                    $w = $w;
            }else{
                    $w = $wdt;
                    $h = $w;
                    $w = ($width / $height) * $w;
            }
    }else{
            // Both width and Height are set.
            // this will reshape to the new sizes.
            $w = $wdt;
            $h = $height;
    }
    $source_image = @file_get_contents($source) or die('Could not open'.$source);
    $source_image = @imagecreatefromstring($source_image) or die($source.' is not a valid image');
    $sw = imagesx($source_image);
    $sh = imagesy($source_image);
    $ar = $sw/$sh;
    $tar = $w/$h;
    if($ar >= $tar){
            $x1 = round(($sw - ($sw * ($tar/$ar)))/2);
            $x2 = round($sw * ($tar/$ar));
            $y1 = 0;
            $y2 = $sh;
    }else{
            $x1 = 0;
            $y1 = 0;
            $x2 = $sw;
            $y2 = round($sw/$tar);
    }
    $slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions');
    imagecopyresampled($slate, $source_image, 0, 0, $x1, $y1, $w, $h, $x2, $y2);
    // If $destination is not set this will output the raw image to the browser and not save the file
    if(!$destination) header('Content-type: image/jpeg');
    @imagejpeg($slate, $destination, 75) or die('Directory permission problem');
    ImageDestroy($slate);
    ImageDestroy($source_image);
    if(!$destination) exit;
    return true;
}

所以,WSOD 意味着它在某种情况下没有消息就死掉了。有任何想法吗?


只是为了验证是post_max_filesize设置为高电平?因为根据 php.net:

如果 post 数据的大小大于 post_max_size,则 $_POST 和 $_FILES 超全局变量为空。这可以通过多种方式进行跟踪,例如通过通过$_GET变量处理数据的脚本,即<form action="edit.php?processed=1">,然后检查是否$_GET['processed'] is set.

需要考虑的事情。

欲了解更多信息,请参阅这个链接并向下滚动到post_max_filesize section

UPDATE

根据我的经验,如果您收到 WSOD,通常会这样做error_reporting and display_errors被关闭或memory_limit正在达到。在顶部的脚本中我通常设置memory_limit到 1024M 以验证这不是问题并打开error_reporting and display_errors...所以将其放在文件上传之前:

error_reporting(E_ALL); // or E_STRICT
ini_set("display_errors",1);
ini_set("memory_limit","1024M");

这通常会消除 WSOD 并为您提供处理错误。

UPDATE

你有没有尝试过脱掉@在所有函数前面进行错误抑制以查看它们是否产生特定错误?另外,执行和输入超时是什么?您能验证正在发送哪些标头吗? (确保它是Content-Type=text/html;)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

move_uploaded_file 不起作用,没有错误 的相关文章