[英]move_uploaded_file doesn't work, no error
我正在运行一个脚本,该脚本使用move_uploaded_file()
移动上传的文件。 我做了好几千次,但由于某种原因,它不起作用。 我已经克服了以下内容:
<form>
using method="post"
并正确使用enctype
777
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
更新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">
。 那么,据我所知,文件没有上传到服务器的临时区域?
更新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
更新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_max_size,则$ _POST和$ _FILES超全局变量为空。 这可以通过各种方式跟踪,例如将
$_GET
变量传递给处理数据的脚本,即<form action="edit.php?processed=1">
,然后检查$_GET['processed']
是否为组。
需要考虑的事情。
有关详细信息,请参阅此链接并向下滚动到post_max_filesize
部分
UPDATE
根据我的经验,如果你得到一个WSOD,通常会关闭error_reporting
和display_errors
或者达到memory_limit
。 在顶部的脚本中,我通常将memory_limit
设置为1024M以验证是不是问题,并启用error_reporting
和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;
)
尝试将目标路径更改为非临时目录。
经过一些更新后,解决方案是:
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
...将其添加到处理上传的文件的开头。
[error] => 1
表示上传的文件超过了php.ini中的upload_max_filesize指令。
http://www.php.net/manual/en/features.file-upload.errors.php
所以,你必须改变你的设置。
至于你在这里发布的php.ini文件,它只是不会影响你的PHP。 你必须将它移动到更合适的位置
上周我遇到了同样的问题,那只是因为我的服务器空间磁盘已经满了! 我希望它会帮助别人......
我有同样的问题,但我想覆盖一个文件,所以我必须删除旧文件,而不是它的工作原理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.