Can't create folders on UNIX

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gotlisch
Forum Newbie
Posts: 23
Joined: Wed Jan 11, 2006 8:37 am

Can't create folders on UNIX

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Can't create folders on UNIX

Post 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.
(#10850)
gotlisch
Forum Newbie
Posts: 23
Joined: Wed Jan 11, 2006 8:37 am

Re: Can't create folders on UNIX

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Can't create folders on UNIX

Post 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.
gotlisch
Forum Newbie
Posts: 23
Joined: Wed Jan 11, 2006 8:37 am

Re: Can't create folders on UNIX

Post by gotlisch »

I'm pretty sure safe_mode is on as it's shared hosting...either way isn't there some way around it??
Post Reply