上传文件在localhost上工作正常,但在notserver上工作

时间:2017-02-02 22:01:05

标签: php html

我在localhost上有一些代码,它们工作正常,但是当我把它们(html,php)放在实时服务器上时,它会堆叠在第一个上传部分, 在php方面:

$target_dir = "wwwroot/aaa/html/temp/";
$target_file = $target_dir . $_FILES["fileToUpload"]["name"];
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (file_exists($target_file)) {
    $exist =  "file has already been uploaded.";
    $uploadOk = 0;
}
if ($uploadOk == 0) {

} else {
    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) {
        $test="uploaded";
    } else {
        $fail="fail uploaded";
    }
    }
$tempfilename=$_FILES['fileToUpload']['tmp_name'];
$array=array("$tempfilename","$fail");
echo json_encode($array);

在HTML方面:

<input type="file" id="fileToUpload" name="fileToUpload"></input>




 $.ajax({
            url: 'loadfile.php',
            type: 'POST',
            data: formData,
            async: false,
            dataType: 'json',
            success: function (html) {
                loadfileName=html[0];
                alert(html[0]+' '+html[1]);
            },
            cache: false,
            contentType: false,
            processData: false
        });

警报总是“/ temp / someRandomCharacters”+“上传失败”,但在localhost上工作正常。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

您要上传的文件夹需要将权限设置为775