- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在运行一个脚本,该脚本使用 move_uploaded_file()
移动上传的文件.我已经这样做了数千次,但由于某种原因它不起作用。我已确认以下内容:
<form>
使用 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>';
}
通过 php.ini hack 使用 1and1 托管 :P
更新 1
我想补充一点,脚本的响应恰好在 60 秒后发生。
更新 2
我们可能会有所进展。就print_r($_FILES)
这是数组的结果:
Array (
[image] => Array (
[name] => P2120267.JPG
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
)
所以这让我相信文件没有正确上传到服务器或其他东西?我查过了,post表单是<form action="" method="post" enctype="multipart/form-data">
.所以,据我所知,文件没有上传到服务器的临时区域?
更新 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
更新 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:
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.
需要考虑的事情。
有关详细信息,请参阅 this link并向下滚动到 post_max_filesize
节
更新
根据我的经验,如果您获得 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 并给您带来错误。
更新
你试过取下@
吗?在所有函数前进行错误抑制以查看它们是否产生特定错误?还有你的执行和输入超时是什么?你能验证发送的是什么标题吗? (确保它是 Content-Type=text/html;
)
关于php - move_uploaded_file 不起作用,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5655859/
脚本: Image uploaded successfully!.'; } else {//if file was not moved. ech
我正在网站上工作,希望用户能够上传文件。所以我正在尝试学习如何做到这一点。经过研究,它说我必须使用函数move_uploaded_file()。我写的代码与示例中的代码一样(更改数据),但是无法正常工
这是我的表格 Admin's Area sponseres list +Add new Sponser &nb
我有一个免费托管网站 - 000webhost.com,它允许您上传图片。 但是,当我尝试上传图片时,出现以下错误: 警告:move_uploaded_file(images/SmallSmileyF
我有一个免费托管网站 - 000webhost.com,它允许您上传图片。 但是,当我尝试上传图片时,出现以下错误: 警告:move_uploaded_file(images/SmallSmileyF
我正在使用带有 mysql 的 wamp 服务器并添加了以下代码 但它没有将文件插入数据库它在数据库中创建名称,在 wamp 文件夹中创建 tmp 文件,但没有将其移动到所需目录 看代码
大家。我在让 PHP 将文件移动到目录中时遇到问题。 mkdir 在创建目录时工作得很好,并且 mysql 表正在插入所有文件。不过,move_uploaded_file 步骤无法正常工作。
我的代码可以成功上传图像。但问题是它无法显示上传的图像。我检查了 html 源 View 中的图像路径输出是否正确,但图像直到不显示。我认为这是一个文件权限问题。我如何上传这些具有读写完全权限的图像,
我正在尝试创建图像 uploader ,但在将图像保存到文件夹中时遇到问题。该文件夹应该位于名为 images 的目录的根目录中吗?如果是这样,当我使用 move_uploaded_file 代码时,
我正在尝试将文件上传到图像文件夹,并将目录路径插入 mysql 数据库。 这是我的 HTML 表单 New Facility ...
我目前有以下内容: if (in_array($_FILES['userfile']['type'], $mimeTypes)) { $target_path = "./uploa
我正在尝试动态上传图片。 HTML 代码是: Select Picture " name="pic"> After I write the following
我正在将我的网站从共享主机迁移到 VPS。在我的 VPS 上进行测试时,我发现突然间我无法再通过网络表单上传文件了。 错误:警告:move_uploaded_file(/uploads/logokle
在 LEMP(Linux CentOS、Nginx、MariaDB、PHP)服务器上,/etc/php.ini 文件具有以下内容。 file_uploads = on upload_tmp_dir =
我一直在编写一个 php 脚本,它创建一个文件夹并将发布的图像保存在创建的文件夹中,文件夹被创建,但图像我没有保存。 下面是脚本: if (isset($_FILES['images'])) {
您好,我正在尝试将图像上传到我的数据库和文件夹以及我表单中的其他元素,一切正常,但我无法让文件出现在上传文件夹中。这是我的代码: if(isset($_POST['submit'])){ //
我正在尝试上传文件,但我的浏览器出现以下错误: Warning move_uploaded_file(public/upload/udesignwptheme138.zip) [function.m
我正在使用下面的脚本,因此用户可以上传他们的个人资料图片。第一次上传图像时(当该位置不存在图像时)效果很好。但是,如果图像已经存在于路径中(如果用户尝试更改个人资料图片),新图像将不会替换旧图像。我确
快速提问 我正在尝试将上传的文件移动到根目录之外的/opt/ffencoderd/data/media 目录,但我得到文件不存在。如果我在同一文件中使用 exec() 在/usr/bin/clamsc
我有 PHP 脚本 (testupload.php): "; if(move_uploaded_file($_FILES['frag3']['name'], $target_path)) {
我是一名优秀的程序员,十分优秀!