View Full Version : simple script to create a dir and copy file to it

12-31-2008, 10:14 AM
hey guys,

I've got a script but its getting overkill now...

Basically I need to create a dynamic directory, using $login as the dir name...

then I need to copy getpics.php from the root of the server to that new dir...


ini_set('display_errors', 1);
// vars
$login = $_GET['login'];
$user = $_GET['user'];

$getpics = "/var/www/vhosts/domain.co.uk/httpsdocs/getpics.php";
$newdir = "/var/www/vhosts/domain.co.uk/httpdocs/clients/$login/getpics.php";
$thisdir = "/var/www/vhosts/domain.co.uk/httpdocs/clients";
$ftpthisdir = "httpdocs/clients";

$dir = $thisdir . DIRECTORY_SEPARATOR . $login;
$ftpdir = $ftpthisdir . DIRECTORY_SEPARATOR . $login;

$ftp_user_name='FTPUSER'; // PUT YOUR FTP USER HERE

// Connection
$conn_id = ftp_connect('domain.co.uk');

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

// connecting
if ($conn_id && $login_result) {

//IF NO DIRECTORY THEN USE FTP TO MKDIR, and copy getpics to new dir
if (!is_dir($dir) ){

// Creating the dir with the FTP user owner
if (ftp_mkdir($conn_id, $ftpdir)) {

if (!copy($getpics, $newdir)) {
echo "failed to copy $getpics";
} else { }

} else { echo "<p class='footer'>Failed to create directory</p>"; }

//Directory is there
} else { echo "<p class='footer'>Directory Exists</p>";
if (!copy($getpics, $newdir)) {
echo "failed to copy $getpics";
} else { }
} else { echo "<p class='footer'>No Connection</p>"; }

// Close connection

so far everything is working except the copy....

the script is an include on a page, but I get this error:

Warning: copy(/var/www/vhosts/domain.co.uk/httpdocs/clients/winning l/getpics.php) [function.copy]: failed to open stream: Permission denied in /var/www/vhosts/domain.co.uk/httpsdocs/photographer/createadmin/create.php on line 41

the getpics.php file is set to 777 and the clients dir is 777, the owner and group are the same as the dir that is created (thats why i used FTP_mkdir...)

any thoughts as to why the copy doesnt work?