move_uploaded_file 不起作用,没有错误
我正在运行一个脚本,该脚本使用 move_uploaded_file()
移动上传的文件。我已经这样做了数千次,但由于某种原因它不起作用。我已确认以下内容:
- 使用
method="post"
和正确的enctype
- 从表单目录引用的正确文件
- 具有权限
- 所有的
memory_limit
、max_execution_time
等都设置为超高设置以避免超时
基本上,下面的脚本仅返回 Your image is也大。
。我还启用了显示所有错误,但仍然没有收到错误。有什么想法吗?
$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
)
)
所以这让我相信文件没有正确上传到服务器或其他什么?我已经检查过,发布表单为
更新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 意味着它在没有消息的情况下某种方式死亡。有什么想法吗?
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:
<form>
usingmethod="post"
and correctenctype
- correct file referenced from form
- directory has permissions
777
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只是为了验证
post_max_filesize
是否设置为高级别?因为根据 php.net:需要考虑的事情。
有关更多信息,请参阅此链接并向下滚动到
post_max_filesize 部分
更新
根据我的经验,如果您遇到 WSOD,通常是由于
error_reporting
和display_errors
被关闭或已达到内存限制。在顶部的脚本中,我通常将
memory_limit
设置为 1024M 以验证这不是问题,然后打开error_reporting
和display_errors
。 ..所以将其放在文件上传之前:这通常会消除 WSOD 并为您提供要处理的错误。
更新
您是否尝试过取消所有函数前面的
@
错误抑制,以查看它们是否产生特定错误?另外,执行和输入超时是什么?您能验证正在发送哪些标头吗? (确保它是Content-Type=text/html;
)Just to verify is the
post_max_filesize
set to a high level? Because according to php.net:Something to consider.
for more info see this link and scroll down to the
post_max_filesize
sectionUPDATE
In my experience if you're getting a WSOD it's usually do to
error_reporting
anddisplay_errors
being turned off OR thememory_limit
being reached. In the script at the top I usually set thememory_limit
to 1024M to verify that isn't the problem and the turn onerror_reporting
anddisplay_errors
... so put this before the file upload: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 isContent-Type=text/html;
)尝试将目标路径更改为非临时目录。
经过一些更新后,这里是解决方案:
...将其添加到处理上传的文件的开头。
Try changing the target path to a non temp directory.
After some of the updates here is the resolution:
...add this to the beginning of your file that processes the upload.
<代码>[错误] => 1 表示上传的文件超出了 php.ini 中的 upload_max_filesize 指令。
http://www.php.net/manual/en/features .file-upload.errors.php
因此,您必须更改设置。
至于您在这里发布的 php.ini 文件,它不会影响您的 PHP。你必须把它移到更合适的位置
[error] => 1
means The uploaded file exceeds the upload_max_filesize directive in php.ini.http://www.php.net/manual/en/features.file-upload.errors.php
So, you have to change your settings.
as for the php.ini file you posted here, it just doesn't affect your PHP. you have to move it somewhere to more proper location
我上周也遇到了同样的问题,那只是因为我的服务器空间磁盘已满!我希望它能帮助某人...
I had the same problem last week, it was just because my server space disk was full! I hope it will help someone...
我遇到了同样的问题,但我想覆盖一个文件,所以我必须删除旧文件,然后它才能工作。
I had same problem, but I wanted to overwrite a file, so I have to delete old file and than it works.