move_uploaded_file不起作用,没有错误 [英] move_uploaded_file doesn't work, no error

查看:171
本文介绍了move_uploaded_file不起作用,没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个脚本,用 move_uploaded_file()来移动上传的文件。我已经做了这么多次,但由于某种原因,这是行不通的。我已经做了以下事情:


  1. < form> using method =post并正确 enctype


  2. 目录的权限 777

  3. 所有 memory_limit max_execution_time 等设置为超高设置,以避免超时

基本上,下面的脚本只返回您的图片太大。。我也启用了所有的错误显示,仍然没有得到一个错误。任何想法?

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

$ target_path = $ target_path。$ time。'。jpg';
$ b $ if if(move_uploaded_file($ _ FILES ['image'] ['tmp_name'],$ target_path)){

} else {
$ error。=' < li>您的图片太大。< / li>';
}

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

$
$ b

UPDATE 1



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

更新2



只要 print_r($ _ FILES),这就是数组的结果:

 <$ c $数组(
[image] =>数组(
[name] => P2120267.JPG
[type] =>
[tmp_name] =>
[错误] => 1
[size] => 0


因此,这导致我相信文件没有正确上传到服务器或什么?我已经检查过,表格是< form action =method =postenctype =multipart / form-data> 。那么,从我所知道的情况来看,这个文件并没有被上传到服务器的临时区域中?

更新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 /'.$时间。 -tmp.jpg,$宽度,$高度); 

在下面的代码中:

<$ p $
if(empty($ height)){
// height is nit($ source,$ destination = NULL,$ wdt,$ height = NULL){
if设置,所以我们保持相同的长宽比。
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 {
//设置宽度和高度。
//这将重新塑造新的尺寸。
$ w = $ wdt;
$ h = $ height;
}
$ source_image = @file_get_contents($ source)或者die('Could not open'。$ source);
$ source_image = @imagecreatefromstring($ source_image)或die($ source。'不是一个有效的图像');
$ 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)或死('无效的缩略图dimmensions');
imagecopyresampled($ slate,$ source_image,0,0,$ x1,$ y1,$ w,$ h,$ x2,$ y2);
//如果未设置$ destination,则会将原始图像输出到浏览器,如果(!$ destination)头('Content-type:image / jpeg'),则不保存文件

@imagejpeg($ slate,$ destination,75)或死(目录权限问题);
ImageDestroy($ slate);
ImageDestroy($ source_image);
if(!$ destination)exit;
返回true;





$ b因此,WSOD意味着它的某种死亡没有消息。任何想法?

解决方案

只需要验证 post_max_filesize 设置为高水平?因为根据php.net:

lockquote
如果post数据的大小大于post_max_size,$ _POST和$ _FILES superglobals是空的。这可以通过各种方式进行跟踪,例如通过将 $ _ GET 变量传递给处理数据的脚本,即< form action =edit.php?processed = 1> / code>,然后检查是否设置了 $ _ GET ['processed']

需要考虑的事情

更多信息请参阅这个链接并向下滚动到 post_max_filesize 部分

按照我的经验,如果你得到一个WSOD,通常是这样的: error_reporting display_errors 被关闭,或者达到 memory_limit 。在顶部的脚本中,我通常将 memory_limit 设置为1024M,以验证是不是问题,并打开 error_reporting display_errors ...所以放在文件上传之前:

 使用error_reporting(E_ALL); //或E_STRICT 
ini_set(display_errors,1);
ini_set(memory_limit,1024M);

通常会抛弃WSOD,并给您和错误提供帮助。 b
$ b

更新

您是否尝试取下 @ 在你所有的函数前面的错误抑制看到他们正在产生一个特定的错误?还有什么是执行和输入超时?你可以验证哪些标题正在发送? (确保它是 Content-Type = text / html;


I am running running a script which moves an uploaded file with move_uploaded_file(). I have done this thousands of times but for some reason it's not working. I have confimred the following:

  1. <form> using method="post" and correct enctype
  2. correct file referenced from form
  3. directory has permissions 777
  4. all the memory_limit, max_execution_time, etc are set to super high settings to avoid timeouts

Basically, the script below returns with just Your image is too big.. I have also enabled ALL errors to display and still don't get an error. Any ideas?

$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>';
}

Using 1and1 hosting with the php.ini hack :P

UPDATE 1

I would like to add that response from the script occurs exactly after 60 seconds.

UPDATE 2

We might be getting somewhere with this. Just print_r($_FILES) and this is the result of the array:

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

So that leads me to believe that the file isn't be uploaded correctly to the server or something? I have checked and the post form is <form action="" method="post" enctype="multipart/form-data">. So, from what I can tell, the file isn't being uploaded to the server's temp area?

UPDATE 3

Noticed the [error] => 1 in the above array. This is apparently down to the filesize being larger than the upload_max_filesize. However, when i set this as 128M, I get a white screen of death after 60 seconds. The file I'm uploading is 2.5MB

Here is my php.ini file:

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

UPDATE 4

With details above, it appears that I am getting a WSOD, but the image is being upoaded. So, how to stop the WSOD? I can't find any errors related anywhere.

UPDATE 5 - FOUND IT!

Shame on me for not giving you guys all the code. It looks like its to do with this line:

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

In the following code:

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;
}

So, WSOD means that its some sort of die without a message. Any ideas?

解决方案

Just to verify is the post_max_filesize set to a high level? Because according to php.net:

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

Something to consider.

for more info see this link and scroll down to the post_max_filesize section

UPDATE

In my experience if you're getting a WSOD it's usually do to error_reporting and display_errors being turned off OR the memory_limit being reached. In the script at the top I usually set the memory_limit to 1024M to verify that isn't the problem and the turn on error_reporting and display_errors... so put this before the file upload:

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

That normally gets rid of the WSOD and gives you and error to work with.

UPDATE

Have you tried taking off the @ error suppression in front of all your functions to see they are producing a specific error? Also what are you execution and input timeouts? and Can you verify what headers are being sent? (make sure it is Content-Type=text/html;)

这篇关于move_uploaded_file不起作用,没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆