Page 1 of 1

Can't create folders on UNIX

Posted: Mon Mar 03, 2008 5:37 pm
by gotlisch
I've utilized a little "uploading java applet" that I found on the web which allows you to upload files to a server by drag and drop. The java applet calls a pretty straight forward upload script which basically creates a folder and saves the uploaded file in that folder. The app. works wonders when I run it locally on my Windows machine - but when I deploy it with on my Unix server (shared hosting) it just doesn't work. It doesn't create the folders nor does it save the file. What is ever weirder is that the PHP script doesn't throw an error. And the mkdir comes back as "true" when I try to debug....

I'm obviously thinking this issue has to do with "A" the development environment and "B" php.ini settings - having said that, I don't have a clue what exactly the problem is...I've included some of the code I'm using below:

Code: Select all

$subfolder = $_GET['placement_id'];
$campaign = $_GET['campaign_id'];
$root = '_files';
 
//create new campaign folder if it doesn't already exist
if(!is_dir ($root.'/'.$campaign)){
mkdir("$root/$campaign", 0777);
}
 
//create new subfolder (for the placement) if it doesn't already exist
if(!is_dir ($root.'/'.$campaign.'/'.$subfolder)){
mkdir("$root/$campaign/$subfolder", 0777);
 
 
} 
 
$save_path = $root.'/'.$campaign.'/'.$subfolder.'/';
 
$file = $_FILES['userfile'];
$k = count($file['name']);
 
 
for($i=0 ; $i < $k ; $i++)
{
    if($i %2)
    {
        echo '<tr bgcolor="#FFFF99"> ';
    }
    else
    {   
        echo '<tr>';
    }
    
    echo '<td align="left">' . $file['name'][$i] ."</td>\n";
    echo '<td align="right">' . $file['size'][$i] ."</td></tr>\n";
 
    if(isset($save_path) && $save_path!="") {
        $name = split('/',$file['name'][$i]);
        
    move_uploaded_file($file['tmp_name'][$i], $save_path . $name[count($name)-1]);
        
 
        
 
    }
    
}
 
echo "<tr style='color: #0066cc'><td>SSL</td><td>". (($_SERVER[HTTPS] != 'on') ? 'Off' : 'On') ."</td></tr>";
if(! isset($save_path) || $save_path =="")
{
    echo '<tr style="color: #0066cc"><td colspan=2 align="left">Files have not been saved, please edit upload.php to match your configuration</td></tr>';
}

If anyone could give me a hint as to to what the problem might be I would be very, very thankful.


Cheers,
Mikael

Re: Can't create folders on UNIX

Posted: Mon Mar 03, 2008 6:33 pm
by Christopher
91.368249% of the time on Unix the problem is that the program does not have write permission to the file/directory. If you are using PHP, remember that the "user" is whatever user the web server runs as.

Re: Can't create folders on UNIX

Posted: Tue Mar 04, 2008 6:48 am
by gotlisch
Hmm..so how do I set the access right of the server then? I have already set the folders access rights to 0777 (read,write,etc.) and I do the same when I create the new folders.

Re: Can't create folders on UNIX

Posted: Tue Mar 04, 2008 7:01 am
by Chris Corbyn
gotlisch wrote:Hmm..so how do I set the access right of the server then? I have already set the folders access rights to 0777 (read,write,etc.) and I do the same when I create the new folders.
The directory this script runs in has been chmod 0777? I assume using FTP/SSH? :)

If it has and this is still happening it's possible safe_mode is on or open_basedir restriction is on.

Re: Can't create folders on UNIX

Posted: Tue Mar 04, 2008 3:48 pm
by gotlisch
I'm pretty sure safe_mode is on as it's shared hosting...either way isn't there some way around it??