【问题标题】:PHP Error, Image resizingPHP错误,图像调整大小
【发布时间】:2013-01-22 17:45:17
【问题描述】:

我正在尝试在将图像上传到服务器之前调整图像大小(又名上传名为“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>

【问题讨论】:

    标签: php


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 2012-01-09
      • 1970-01-01
      • 2012-08-15
      • 2014-01-25
      • 2011-03-31
      • 2011-08-30
      相关资源
      最近更新 更多