傳輸到我上傳文件夾的文件運行良好,但我在mkdir中有警告。它說文件存在,但圖片和文件夾生成自己的名字。我不知道什麼警告正在確定。警告: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)){
$qry = "INSERT INTO files (code, name, path, type) VALUES ('$dir','$uniq_name','$dest','$ext')" ;
$result = mysqli_query($dbc, $qry);
if (false===$result) {
$sql_error .= 'Error in the query '.$qry.' Error Desc :'.mysqli_error($dbc).'<br /><br />' ;
}
}
}
}
}}
我使用,如果{的mkdir($路徑,0700)(file_exists($ PATH)!); }但它只上傳1張圖片,即使我上傳了多張。先生,我該怎麼辦?對不起我的語法。這不是我的第一語言。 – clien
您必須從文件名中分離文件夾的路徑.. @ user3199128 – Erik