gpt4 book ai didi

php - 警告 : mkdir(): File exists

转载 作者:IT王子 更新时间:2023-10-29 00:20:17 26 4
gpt4 key购买 nike

传输到我的上传文件夹的文件工作正常,但我在 mkdir 中收到警告。它说文件存在但图片和文件夹生成自己的名称。我不知道什么警告正在确定。

include 'connect.php';

$dir = substr(uniqid(), -7); // Uniqid for subdirectory

$path = "uploads/$dir/"; // uploads/subdirectory/ // Make directory

$valid_formats = array("jpg", "png", "jpeg", "kml");

$max_file_size = 2097152;

$count = 0;

// Loop $_FILES to execute all files

if (!empty($_FILES)) {
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}

if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
} elseif (!in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)) {
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
} else { // No error found! Move uploaded files
mkdir($path, 0700);
$ext = pathinfo($_FILES['files']['name'][$f], PATHINFO_EXTENSION);
$uniq_name = substr(uniqid(), -5) . '.' . $ext;
$dest = $path . $uniq_name;

if (move_uploaded_file($_FILES["files"]["tmp_name"][$f], $dest)) {
// more logic
}
}
}
}
}

最佳答案

警告非常明确,您正在创建已经存在的目录。所以,只需将其更改为

if (!file_exists($path)) {
mkdir($path, 0700);
}

关于php - 警告 : mkdir(): File exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22032345/

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