Crookers
Crookers

Reputation: 67

Cannot create directory with mkdir

I have got the upload_files script below to work on my development server (XAMPP Apache 2.4.17 and PHP 5.6.23) but I cannot get it to work on my production server (Synology diskstation, apache 2.2.31 php 5.6.30)

It cannot create the directory SY2017_18 in the data directory (the data directory DOES exist). The data directory has the following permissions: drwxrwxr-x 1 admin users 234 Aug29 09:59 data

I have checked php.ini and:

file_uploads = On
upload_tmp_dir = "var/services/tmp"

Any help greatly appreciated.

// upload_files script
if(isset($_FILES['my_file'])){    
    $errors= array();
    $file_name = $_FILES['my_file']['name'];
    $file_size =$_FILES['my_file']['size'];
    $file_tmp =$_FILES['my_file']['tmp_name'];
    $file_type=$_FILES['my_file']['type'];
    $file_ext=strtolower(end(explode('.',$_FILES['my_file']['name'])));
    $extensions= array("jpg","png");

if(in_array($file_ext,$extensions)=== false){
    $errors[]="extension not allowed, please choose a Spreadsheet file.";
}

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

if(empty($errors)==true){
    $folder = $_SERVER['DOCUMENT_ROOT']."/pdo/data/SY".$thisschoolyear;
    if(!is_dir($folder)){
        if (mkdir($folder, 0755)) {
        } else echo "NO luck creating the folder $folder<br>";
    }
}

}

Upvotes: 3

Views: 1150

Answers (1)

Muhammad Noman
Muhammad Noman

Reputation: 156

Make sure the directory in which your code is creating $folder, has it's owner set to Apache.

The best buck would be to check if you are getting any permission etc notices by ini_setting like this (only if errors are off) on top of your script.

ini_set("display_errors", 1);
error_reporting(E_ALL & ~E_NOTICE);

This will display notices too.

Good luck!

Upvotes: 2

Related Questions