php mkdir 目录已存在,php – 警告:mkdir():文件存在

标签:php

传输到我的上传文件夹的文件运行良好,但我在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).'
' ;

}

}

}

}

}}

解决方法:

警告很明显,您正在创建已存在的目录.所以,只需将其更改为

if (!file_exists($path)) {

mkdir($path, 0700);

}

标签:php

来源: https://codeday.me/bug/20191001/1837430.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值