无法在服务器上传文件 - PHP

时间:2014-11-18 19:25:55

标签: php file file-upload

我正在尝试从多上传表单上传文件。尽管$ target_file输出显示正确的文件路径,但文件未上传到服务器。这是代码:

<?php
for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
        $target_dir = '../conference/files/'. $row['CONFERENCE_ID'] .'/';
        $target_file = $target_dir . basename($_FILES['file']['name'][$i]);
        $uploadOk = 1;
        $fileTypeExtension = pathinfo($target_file,PATHINFO_EXTENSION);
        // Check if file already exists
        if (file_exists($target_file)) {
            echo "Sorry, file already exists.";
            $uploadOk = 0;
        }
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["file"]["name"][$i], $target_file)) {
                echo "The file ". basename( $_FILES['file']['name'][$i]). " has been uploaded.";
            } else {
                echo "Sorry, there was an error uploading your file. ";
                echo $target_file;
            }
        }
}
?>

更新:我添加此代码以检查文件是否已上传且结果为否。任何想法为什么会发生这种情况?

if (is_uploaded_file($_FILES['file']['name'][$i])) {
            echo "Temp file uploaded. \r\n";
} else {
            echo "Temp file not uploaded. \r\n";
}

更新2:我试图只上传一个文件,它工作正常。问题在于多个文件。 xampp版本可以成为问题吗?

0 个答案:

没有答案