ローカルホストでスクリプトを使用してファイルのアップロードを開始したところです。
しかし、ファイルをアップロードするたびにエラーが発生します:
警告: chmod() [function.chmod]: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/admin/upload.php on line 5
警告: chmod() [function.chmod]: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/admin/upload.php on line 6
許可とパスに問題があると思いますが、それを解決する方法がわかりません、私のコード:
<?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;
}
}
?>