我只是使用我的localhost中的脚本启动上传文件,
但每次我想上传文件时都会出错:
警告:chmod()[function.chmod]:第5行/Applications/XAMPP/xamppfiles/htdocs/admin/upload.php中没有此类文件或目录
警告: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;
}
}
?>
答案 0 :(得分:1)
chmod(realpath(dirname(__FILE__)).'/uploads', 0777);
chmod(realpath(dirname(__FILE__)).'/uploads/'.$name, 0777);