0

I am trying to create directories for better file organization. The front-end for this is a form where a user will input the title, content and the region(dropdown menu). When the user submit the form, the data will be taken to a file named save.php and will be processed. Below are the codes on the save.php file. Actually the main goal for this is to produce an html file and then organize these html files into folders by region. I cant make the mkdir() to work. The message "directory created" is always printed out but there is no actual folder created. What do you think is the problem on my code? What I want to happen is that when the user clicks on the "submit" button, folders with region names will be created. Please help? Or any suggestion or another way to solve this problem?

$ad_title = $_POST['title'];
$ad_content = $_POST['content-ads']; 
$ad_region = $_POST['region']; 

if (!is_dir("uploads/"$ad_region)) {
        // dir doesn't exist, make it
        mkdir("uploads/".$ad_region);
        echo "directory created!";
    }
    else {
        echo "directory already exist!";
    }

EDIT: I dont know if this matters but my save.php file and the uploads folders where the codes above is saved in the local directory

localhost/system/modules/new

When I relocated the save.php file and the uploads folder in the directory

localhost/system/

all seems to be working now.But I want it to work in the localhost/system/modules/new directory for better organization. Any help on this?

4

3 回答 3

0

Try giving it the absolute path..

You're also missing a dot in is_dir; Should be !is_dir("uploads/" . $ad_region

于 2013-09-23T02:51:49.413 回答
0

您在检查目录是否存在时缺少连接期

if (!is_dir("uploads/"$ad_region)) {if (!is_dir("uploads/" . $ad_region)) {

加上为遗嘱添加权限mkdir(path, permission, recursive)可以防止令人头疼的事情;

于 2013-09-23T02:58:40.107 回答
0

通常,当未在 Web 应用程序中创建目录时,您正在处理权限问题。

确保运行 Web 服务的用户(如果是 Linux,通常是“apache”或“www-data”)允许在您尝试创建目录的位置创建目录。

于 2013-09-23T02:59:40.800 回答