3

请帮助使用php代码:

我有以下代码只上传 360x514 图像。我的问题是:如何编辑它以使任何大小都可以上传而不会出现错误消息?

<?php
$MAXIMUM_FILESIZE = 5 * 1024 * 1024; 
$uploaddir = './uploads/image/large_image/'; 
$file = $uploaddir . basename($_FILES['image2']['name']); 
$raw_file_name= $_FILES['image2']['tmp_name'];
list($width, $height) = getimagesize($_FILES['image2']['tmp_name']);
if ($width==360 && $height==514) {
if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
echo "success"; 
} 
else {
echo "error";
}
}else {
echo "size_error";
}
?>
4

2 回答 2

6

就像@Musa 所说,删除检查:

<?php
$uploaddir = './uploads/image/large_image/'; 
$file = $uploaddir . basename($_FILES['image2']['name']); 
$raw_file_name = $_FILES['image2']['tmp_name'];
if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
    echo "success"; 
} else {
    echo "error";
}
于 2012-11-12T20:32:43.740 回答
1
list($width, $height) = getimagesize($_FILES['image2']['tmp_name']);
if ($width==360 && $height==514) {
    if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
        echo "success"; 
    } 
else {
    echo "error";
}

如果您阅读它,它就在您的代码中...这里说它必须等于 360x514,只需摆脱该 IF 语句,然后跳到 move_uploaded_file 命令。

于 2012-11-12T20:31:49.440 回答