在php中存储图像文件

时间:2012-08-11 18:47:56

标签: php image file upload store

我正在尝试将我的文件保存在根目录中。但我一直低于错误。

警告:move_uploaded_file(../ upload / dddd1.png)[function.move-uploaded-file]:无法打开流:/ Applications / MAMP / htdocs / test-website中没有这样的文件或目录第48行的/process/uploadchecker.php

我想将图片保存到: /应用/ MAMP / htdocs中/测试的网站/上传

bellow是我的PHP代码。

 $allowedExts = array("jpg", "jpeg", "gif", "png");
                $extension = end(explode(".", $_FILES["upload_file"]["name"]));

                if ((($_FILES["upload_file"]["type"] == "image/gif")|| ($_FILES["upload_file"]["type"] == "image/jpg")||($_FILES["upload_file"]["type"] == "image/jpeg")|| ($_FILES["upload_file"]["type"] == "image/png"))&& ($_FILES["upload_file"]["size"] < 200000)&& in_array($extension, $allowedExts)){
                   if ($_FILES["upload_file"]["error"] > 0){
                        echo "Error: " . $_FILES["upload_file"]["error"] . "<br />";
                    }else{
                    echo "Upload: " . $_FILES["upload_file"]["name"] . "<br />";
                    echo "Type: " . $_FILES["upload_file"]["type"] . "<br />";
                    echo "Size: " . ($_FILES["upload_file"]["size"] / 1024) . " Kb<br />";
                    echo "Stored in: " . $_FILES["upload_file"]["tmp_name"];


                        if (file_exists("../uploads/" . $_FILES["upload_file"]["name"]))
                          {
                          echo $_FILES["upload_file"]["name"] . " already exists. ";
                          }
                        else
                          {
                          move_uploaded_file($_FILES["upload_file"]["tmp_name"],"../upload/" . $_FILES["upload_file"]["name"]);
                          echo "Stored in: " . "../uploads/" . $_FILES["upload_file"]["name"];
                          }

                   }
                  }else{
                    echo "Invalid file";
                  }

1 个答案:

答案 0 :(得分:1)

你的文件移动路径是你必须使用上传目录

 move_uploaded_file($_FILES["upload_file"]["tmp_name"],"../upload/" . $_FILES["upload_file"]["name"]);

使用

<强>上传

插入

上传

试试这个

move_uploaded_file($_FILES["upload_file"]["tmp_name"],"../uploads/" . $_FILES["upload_file"]["name"]);