dongzangchui2072 2014-02-26 05:11
浏览 335

警告:mkdir():文件存在[关闭]

The file transferring to my upload folder is working well but I have a warning in mkdir. It says file exist but the picture and folder generates own name. I don't know what warning is determining.

Anyone can help me?

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 />' ;
                }
            }

        }

    }       
}}
  • 写回答

2条回答 默认 最新

  • dongtazu3080 2014-02-26 05:15
    关注

    Warning is quite clear, you are creating directory which already exists. So, just change it to

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

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等