2011-04-13 76 views
7

我正在运行一个脚本,它移动上传文件时使用move_uploaded_file()。我已经做了这么多次,但由于某种原因,它无法正常工作。我已经confimred如下:使用method="post"和正确enctypemove_uploaded_file不起作用,没有错误

  1. <form>
  2. 从形式引用
  3. 正确的文件
  4. 目录有权限777
  5. 所有memory_limitmax_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的黑客主机:P

更新1

我想从脚本发生正好60秒后补充一点反应。

更新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。这显然低至the filesize being larger than the 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?我找不到任何相关的错误。

UPDATE 5 - FOUND IT!

对我没有给你们所有的代码感到羞耻。它看起来像它与这条线做:

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意味着它没有消息的某种死亡。有任何想法吗?

+1

尝试'print_r($ _ FILES);'查看完整的FILES数组。它可能包含错误代码。你的错误信息并没有真正有意义,因为你没有做大小检查,*每个错误条件都会返回“图像太大” – 2011-04-13 21:33:07

+0

文件名可能无效。该文件密钥集? – 2011-04-13 21:33:27

+0

如果你没有得到任何错误消息,请尝试'copy()'而不是'move_uploaded_file()'。在这种情况下也可以看一下'error.log'。 – mario 2011-04-13 21:34:02

回答

9

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

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

需要考虑的事情。

更多信息见this link和向下滚动到​​部分

UPDATE

以我的经验,如果你得到一个WSOD它通常做error_reportingdisplay_errors被关闭或memory_limit达到。在顶部的脚本,我通常设置memory_limit到1024M,以确认是不是该问题,并error_reportingdisplay_errors转弯......这样的文件上传之前把这个:

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

通常出手的WSOD,并给你和错误的工作。

UPDATE

你试过取下@错误抑制的所有功能前,看看他们生产的特定错误?你还有什么是执行和输入超时?你可以验证哪些头文件正在发送? (确保它是Content-Type=text/html;

+0

是的,其设置为256M。当我补充说60秒后我得到了“死亡白屏”。 – David 2011-04-14 06:51:02

+0

看到上面的更新,你可能会找到一些东西。 – David 2011-04-14 07:09:55

+0

完成了所有这些,仍然没有错误,仍然得到相同的错误= 1 – David 2011-04-14 16:54:09

3

尝试将目标路径更改为非临时目录。

后这里的一些更新的是分辨率:

set_time_limit(0); 
ini_set('upload_max_filesize', '500M'); 
ini_set('post_max_size', '500M'); 
ini_set('max_input_time', 4000); // Play with the values 
ini_set('max_execution_time', 4000); // Play with the values 

...添加到你的文件的开头处理该上传。

+0

它上传到的临时目录是我自己创建的目录,而不是系统临时目录。 – David 2011-04-14 06:51:34

+0

您是否尝试添加上述内容?该设置适用于所有上传位置。 – 2011-05-09 14:35:09

+0

您的代码有效。谢谢 – 2016-11-28 03:16:01

0

上周我有同样的问题,这只是因为我的服务器空间磁盘已满!我希望它会帮助别人...

0

我有同样的问题,但我想覆盖一个文件,所以我必须删除旧文件,而不是它的工作原理。