小编sla*_*dje的帖子

在php中创建目录

我有一个问题,当我想上传图片和创建一个不存在的新目录它不会使文件夹$ gallery_name,它存储上传/ galerije/$用户名的图片而不是uploads/galerije/$ username/$ gallery_name.谁能帮我?

$username = $_SESSION['username'];
$gallery_name = $_POST['gallery_name'];

if (isset($_FILES['files'])) {
    $errors = array();
    foreach ( $_FILES['files']['tmp_name'] as $key => $tmp_name ) {
        $file_name = $key . $_FILES['files']['name'][$key];
        $file_size = $_FILES['files']['size'][$key];
        $file_tmp = $_FILES['files']['tmp_name'][$key];
        $file_type = $_FILES['files']['type'][$key];

        if ($file_size > 2097152) {
            $errors[] = 'File size must be less than 2 MB';
        }

        $desired_dir = "uploads/galerije/" . $username . "/" . $gallery_name;

        if (empty($errors)) {
            if (!is_dir($desired_dir)) {
                mkdir($desired_dir, 0777); // Create directory if it does not …
Run Code Online (Sandbox Code Playgroud)

php

0
推荐指数
1
解决办法
118
查看次数

标签 统计

php ×1