0

我正在尝试在将图像上传到服务器之前调整图像大小(又名上传名为“upload”的文件),并在http://www.white-hat-web-design.co.uk/blog找到了 php 调整图像大小的教程/resizing-images-with-php/ .我试图将它与我的上传功能集成,但图像没有改变。我能做些什么来解决它?我使用 php 5.3 和 HeidiSQL。

error_reporting (E_ALL ^ E_NOTICE);
$allowedExts = array("jpg", "jpeg", "gif", "png");
$parts = explode('.', $_FILES["file"]["name"]);
$extension = end($parts);   
if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/png")|| ($_FILES["file"]["type"] == "image/pjpeg"))&& in_array($extension, $allowedExts)){
if ($_FILES["file"]["error"] > 0){
$mesaj= "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
$nume= $_FILES["file"]["name"];
if (file_exists("../upload/" . $_FILES["file"]["name"])){
$mesaj= $_FILES["file"]["name"] . " already exists. ";
}
else{ $image = new SimpleImage();
$image->load($_FILES['file']['tmp_name']);
$image->resizeToWidth(150);
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/" . $_FILES["file"]["name"]);
$mesaj= "Stored in: " . "upload/" . $_FILES["file"]["name"];
mysql_query("INSERT INTO imagini (nume) VALUES ('$nume')"); 
} 
} 
<form action="<?php $_PHP_SELF ?>" method="post" enctype="multipart/form-data">
    <label for="file">Poza</label><input type="file" name="file" /> 
    <input type="submit" value="Adauga imagine" class="buton_imagine" />
</form>
4

1 回答 1

0

move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $image);

$image是您需要更改$image为的对象$_FILES['file']['name']

于 2013-01-22T09:39:29.773 回答