PHP错误,图像大小调整

时间:2013-01-22 09:37:43

标签: php

我正在尝试在将图像上传到服务器之前调整图像大小(也就是名为“upload”的上传文件),并发现在http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/.I调整图像大小的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>

1 个答案:

答案 0 :(得分:0)

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

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

相关问题