我在根文件夹上完成了chmod -R 777
,但我仍然无法成功
上传(因此,写入)上传的文件夹!
我是否还必须更改php.ini文件?
//$target_path = "http://localhost/photoServerProject/uploaded";
$target_path = "/photoServerProject/uploaded";
$fname = $_FILES["file"]["name"];
$upload_location = $target_path.'/'.$fname;
move_uploaded_file($_FILES["file"]["tmp_name"], $upload_location);
echo 'Moving file: ' . $fname . '</br></br>to: ' . $upload_location;
//echo "<img src=$upload_location>";
if(is_writeable($upload_location)){
echo '</br></br>Location <strong>is</strong> writeable ';
} else {
echo '</br></br>Location <strong>is NOT</strong> writeable ';
}
移动文件:camera.jpeg
to:/photoServerProject/uploaded/camera.jpeg
位置不可写
答案 0 :(得分:0)
尝试使用
$targetPath= $_SERVER['DOCUMENT_ROOT'] . "photoServerProject/uploaded"
或
$targetPath= $_SERVER['DOCUMENT_ROOT'] . "/photoServerProject/uploaded"
答案 1 :(得分:0)
我混淆了本地驱动器与服务器路径之间的路径差异。我的服务器路径的根文件夹(localhosts)与我的本地目录结构不同。
答案 2 :(得分:0)
我误解了服务器和本地磁盘目录结构之间的区别。即,根文件夹是不同的。
我很惊讶没有人提出这个问题。
以下是解决方案:
<?php
$local_target = "~/webdev/photoServerProject/uploaded/";
$server_target = $_server['DOCUMENT_ROOT'] . "/photoServerProject/uploaded/";
$fname = $_FILES["file"]["name"];
$local_file_location = $local_target.$fname;
$server_file_location = $server_target.$fname;
move_uploaded_file($_FILES["file"]["tmp_name"], $local_file_location);
echo 'Moving file: ' . $fname . '</br></br>to local path: ' . $local_file_location;
echo '</br></br> But on the server it resides in : ' . $server_file_location;
echo '</br></br> See?';
echo "</br></br> <img src=$server_file_location>";
?>