我剛開始在我的本地腳本上傳文件,未能打開流:沒有這樣的文件或目錄,權限問題
,但我想每次上傳的文件我給了一個錯誤:
警告命令:chmod()[function.chmod]:在/Applications/XAMPP/xamppfiles/htdocs/admin/upload.php線沒有這樣的文件或目錄5
警告:CHMOD()[function.chmod]:沒有這樣的文件或目錄位於第6行的/Applications/XAMPP/xamppfiles/htdocs/admin/upload.php上
我猜許可和路徑問題,但我不知道如何解決它, 我的代碼:
<?php
define("UPLOAD_DIR",realpath(dirname(__FILE__)).'/uploads');
// set proper permissions on the new file
chmod(realpath(dirname(__FILE__)).'/uploads', 0777);
chmod(realpath(dirname(__FILE__)).'/uploads/'.$name, 0777);
if (!empty($_FILES["myFile"])) {
$myFile = $_FILES["myFile"];
if ($myFile["error"] !== UPLOAD_ERR_OK) {
echo "<p>An error occurred.</p>";
exit;
}
// ensure a safe filename
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
// don't overwrite an existing file
$i = 0;
$parts = pathinfo($name);
while (file_exists(UPLOAD_DIR . $name)) {
$i++;
$name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
}
// preserve file from temporary directory
$success = move_uploaded_file($myFile["tmp_name"],
UPLOAD_DIR . $name);
if (!$success) {
echo "<p>Unable to save file.</p>";
exit;
}
}
?>
在你的代碼的開頭設置的權限。並且您必須使用0777,而不僅僅是777. –
我現在編輯代碼我給出了另一個錯誤,請檢查上面的帖子, – Radian
指定完整路徑,不僅僅是「/ uploads /」。下面的答案似乎是正確的。 –