gpt4 book ai didi

php - 无法打开流 : No such file or directory , 权限问题

转载 作者:行者123 更新时间:2023-11-29 13:30:06 24 4
gpt4 key购买 nike

我刚刚开始使用本地主机中的脚本上传文件,

但是每次我想上传文件时都会出现错误:

警告: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;
}



}
?>

最佳答案

chmod(realpath(dirname(__FILE__)).'/uploads', 0777);

chmod(realpath(dirname(__FILE__)).'/uploads/'.$name, 0777);

关于php - 无法打开流 : No such file or directory , 权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19585605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com