无法move_uploaded_file甚至不执行

时间:2011-12-19 04:30:52

标签: php

我对PHP很新,我试图通过move_uploaded_file函数上传图像,请查看代码部分,请帮忙。顺便说一下,如果它是nessecary,我正在使用IE8:

$name = $_FILES['fileToUpload']['name'];
$basename = @basename($name);
$msg .= " File Name: ". $_FILES['fileToUpload']['name'] .", ";
$msg .= " File Size: ". @filesize($_FILES['fileToUpload']['tmp_name']);
if (isset($_GET['id'])) {
 $id = $_GET['id'];
 //check and/or create dir for user images
 if (!is_dir("uploads\\".$id."\\images")) {
 $dir = "uploads\\".$id."\\images";
 mkdir($dir, 0777);
 if (!move_uploaded_file($basename, $dir)){$msg = "COULD NOT MOVE FILE";}
}
}

$ msg“COULD NOT MOVE FILE”未执行且文件尚未移动 提前谢谢。

2 个答案:

答案 0 :(得分:0)

使用完整路径可能有所帮助,以及双反斜杠的原因,也许这是一个windows事物。我想你正在执行它的目录是不可写的,并且它无法使用mkdir创建你要求它的目录,因此无法创建该文件。

答案 1 :(得分:0)

尝试:

//check if you have form enctype="multipart/form-data" in your form as well
$name = $_FILES['fileToUpload']['name'];
    $basename = @basename($name);
    $msg .= " File Name: ". $_FILES['fileToUpload']['name'] .", ";
    $msg .= " File Size: ". @filesize($_FILES['fileToUpload']['tmp_name']);
    if (isset($_GET['id'])) {
     $id = $_GET['id'];
         //check and/or create dir for user images
         if (!is_dir("uploads/".$id."/images")) {
             $dir = "uploads/".$id."/images";
             mkdir($dir, 0777);
             if (!move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $dir."/".$basename)){$msg = "COULD NOT MOVE FILE";}
        }
    }