PHP文件上传失败

时间:2012-07-26 05:58:59

标签: php mysql

我正在尝试创建一个允许用户将图像上传到服务器的脚本。我已经实现了脚本,但是一旦我尝试上传图像,脚本就会完成,但服务器上不会显示任何图像。有什么想法吗?

PHP:

<?php
require_once("connect.php");
ini_set('display_errors', 'on'); 
error_reporting(E_ALL);

echo __LINE__;

$allowedExtensions = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["image"]["name"]));
print_r($_FILES['image']);
echo $extension;

if((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"]=="image/pjpeg") || ($_FILES["image"]["type"] == "type/png")) && ($_FILES["image"]["size"] <= 102400) && in_array($extension, $allowedExtensions)) {

        echo __LINE__;
        if($_FILES["image"]["error"] > 0) {
                $fileUploadFail = true; 
        }
        else {
               chmod("uploadImages/", 0755);
               move_uploaded_file($_FILES["image"]["tmp_name"], "uploadImages/" . $_FILES["image"]["name"]);
        }

} else {
        $fileUploadFail = true;
        echo __LINE__;
}   
        $fileName = $_FILES["image"]["name"];
        chmod("uploadImages/", 0600);
        echo __LINE__;
        /*if($fileUploadFile) {
              header("Location: uploadArt.php");
        }
        else {
             $title = $_POST['title'];
             $description = $_POST['description'];
             mysql_query("INSERT INTO `Art`(`File Name`, `Description`, `uploadLocation`, `Index`) VALUES('$title', '$description', 'uploadImages/$fileName', '')");
              header("Location: viewArt.php");
        }*/
  ?>

我收到的输出:

6Array ( [name] => comps_tech.png [type] => image/png [tmp_name] => /tmp/phpgQKnMJ [error] => 0 [size] => 661 ) png2529

HTML:

<form id = "uploadDesigns"  enctype="multipart/form-data" name="Upload" method="post" action="fileUpload.php" >
<label for="title">Enter name of design:</label><input type = "text" id = "title" name = "title" size="50"><br /><br />
<label for="image">Upload image:<br />(max 100KB)</label> <input type = "file" id = "image" size = "51" name = "image"><br /><br />
<label for="description">Description:</label> <textarea id = "description" name = "description" rows = "4" cols = "20"></textarea><br /><br />
<button type="submit">Submit Art</button>
</form>

谢谢!

3 个答案:

答案 0 :(得分:3)

你有

input type = "file" id = "image" size = "51" name = "image"

但正在引用

$_FILES["file"]["type"] 

$ _FILES中的“文件”是指文件输入的名称。这是“图像”,而不是“文件”


完成答案(修复其他问题和调试后);最后一个错误是

$_FILES["image"]["type"] == "image/png"

需要添加到if语句中。

答案 1 :(得分:0)

您需要为uploadImages提供写入权限。

答案 2 :(得分:0)

Ur文件目录结构应该是这样的。

1)test.php 2)uploadImages /(此文件夹需要由你创建)。