move_uploaded_file不起作用,没有错误 [英] move_uploaded_file doesn't work, no error
问题描述
我正在运行一个脚本,用 move_uploaded_file()
来移动上传的文件。我已经做了这么多次,但由于某种原因,这是行不通的。我已经做了以下事情:
-
< form>
usingmethod =post
并正确enctype
-
- 目录的权限
777
- 所有
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意味着它的某种死亡没有消息。任何想法?
只需要验证 需要考虑的事情 更多信息请参阅这个链接并向下滚动到 按照我的经验,如果你得到一个WSOD,通常是这样的: 通常会抛弃WSOD,并给您和错误提供帮助。 b 更新 您是否尝试取下 I am running running a script which moves an uploaded file with Basically, the script below returns with just 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 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 UPDATE 3 Noticed the Here is my php.ini file: 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: In the following code: So, WSOD means that its some sort of die without a message. Any ideas? Just to verify is the 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 Something to consider. for more info see this link and scroll down to the UPDATE In my experience if you're getting a WSOD it's usually do to That normally gets rid of the WSOD and gives you and error to work with. UPDATE Have you tried taking off the 这篇关于move_uploaded_file不起作用,没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 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
部分
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);
$ b
@
在你所有的函数前面的错误抑制看到他们正在产生一个特定的错误?还有什么是执行和输入超时?你可以验证哪些标题正在发送? (确保它是 Content-Type = text / html;
)move_uploaded_file()
. I have done this thousands of times but for some reason it's not working. I have confimred the following:
<form>
using method="post"
and correct enctype
777
memory_limit
, max_execution_time
, etc are set to super high settings to avoid timeoutsYour 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>';
}
print_r($_FILES)
and this is the result of the array:Array (
[image] => Array (
[name] => P2120267.JPG
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
)
<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?[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.5MBregister_globals=off
memory_limit = 128M
max_execution_time=3600
post_max_size = 128M
upload_max_filesize= 128M
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;
}
post_max_filesize
set to a high level? Because according to php.net:
$_GET
variable to the script processing the data, i.e. <form action="edit.php?processed=1">
, and then checking if $_GET['processed']
is set.post_max_filesize
sectionerror_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");
@
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;
)