【问题标题】:How to upload images to separate folders?如何将图像上传到单独的文件夹?
【发布时间】:2019-12-18 19:52:50
【问题描述】:

如何将表单中插入的图像上传到服务器,每次新上传都会在主目录中创建新文件夹并将其命名为例如 i1、i2、i3...?

现在我上传的内容正在保存到主文件夹,所以我需要将其分开。

$targetDir = "images/";
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

【问题讨论】:

    标签: image server directory upload


    【解决方案1】:

    您可以使用函数创建文件夹,并将其添加到您的 php 代码中

    if (!file_exists('path/to/directory')) {
        mkdir('path/to/directory', 0777, true);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-10
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 2018-12-20
      相关资源
      最近更新 更多