Jump to content

chmod sub directories not working


fohanlon

Recommended Posts

Hi

 

I want to be able to upload files to subdrectories on the server.  I do not want to set any folders to permanently 0777.

 

Here is what I have so far, its a combo of my own and somw stuff found on the web.  It will chmod the parent folder but fails on the sub folder.  I read about creating the parent folder using FileZila can create problems.  Confused as to what to create the parent folders in.

 

Thanks in advance.

F

 

// documents

$path_to_parent = "/httpdocs/sub1/subs2/";

$parent_folder = "myfiles/";

$sub_folder = $parent_folder . $subdirectoryid;

 

function chmod_open()

{

$ftp_details['ftp_user_name'] = FTP_USER;

$ftp_details['ftp_user_pass'] = FTP_PASS;

$ftp_details['ftp_root'] = FTP_ROOT;

$ftp_details['ftp_server'] = FTP_SERVER;

 

extract ($ftp_details);

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

 

return $conn_id;

}

 

function chmod_file($conn_id, $permissions, $path)

{

$ftp_root = '/httpdocs/sub1/sub2/';

if (ftp_site($conn_id, 'CHMOD ' . $permissions . ' ' . $ftp_root. $path) !== false)

{

return TRUE;

}

else

{

return FALSE;

}

}

 

function chmod_close($conn_id)

{

ftp_close($conn_id);

}

 

// Connect to the FTP

$conn_id = chmod_open();

 

// create folder if it does not exist

if(!file_exists($_SERVER{'DOCUMENT_ROOT'} . $path_to_parent . $sub_folder))

{

chmod_file($conn_id, 777, $parent_folder);

mkdir($sub_folder, 0755);

chmod_file($conn_id, 755, $parent_folder);

}

 

if(file_exists($_SERVER{'DOCUMENT_ROOT'} . $path_to_parent . $sub_folder))

{

echo chmod_file($conn_id, 777, $parent_folder) ? 'CHMODed successfully!<br>' : 'Error<br>';

echo chmod_file($conn_id, 777, $sub_folder) ? 'CHMODed successfully!<br>' : 'Error<br>';

 

// upload files here - docupload

if($_FILES['docupload']['size'] != 0)

{

$tempname = $_FILES['docupload']['tmp_name'];

$actual_filename = $_FILES['docupload']['name'];

$search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");

$replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");

$actual_filename = str_replace($search, $replace, $actual_filename);

if(!move_uploaded_file($tempname, $sub_folder . "/" . $actual_filename)) echo "failure<br>"; else echo "success<br>";

}

 

// delete files here if applicable - delete_file[]

if(count($_REQUEST['delete_file']) > 0)

{

for($i=0; $i < count($_REQUEST['delete_file']); $i++)

{

$f = $_REQUEST['delete_file'][$i];

unlink($f);

}

}

 

echo chmod_file($conn_id, 755, $parent_folder) ? 'CHMODed successfully!<br>' : 'Error<br>';

echo chmod_file($conn_id, 755, $sub_folder) ? 'CHMODed successfully!<br>' : 'Error<br>';

}

 

// Close the connection

chmod_close($conn_id);

 

 

 

Link to comment
Share on other sites

Do you have the ability to log into the web server and use a console?  If so you should just switch to the web server's user id and group and try to make the directories as a permissions test.

 

Otherwise I suggest you make a tiny PHP script called t.php and play with the mkdir and chmod functions until you get something that works the way you'd like.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.