0

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

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

我想将图像保存到:/Applications/MAMP/htdocs/test-website/uploads

下面是我的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";
                  }
4

1 回答 1

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"]);
于 2012-08-11T18:55:16.630 回答