Asked  1 Year ago    Answers:  5   Viewed   13 times

I'm trying to write a PHP script to copy the files from your local machine to a server:

$destination_directory = 'I:pathtofile' . $theme_number;

if(!@opendir($desination_directory)) { echo 'Sorry, the destination directory could not be found.'; die(); }

I check the access to the destination folder with that process, and I keep getting the error return. Anyone know what I'm doing wrong? I pretty much have everything else in place. I just don't know how to access this other server.

Addendum: I accepted an answer below, because it is technically correct, and I was able to get the Apache server to be accepted by the IIS server, however, for what I was trying to accomplish (giving anyone who used the script unfettered ability to move files to the server), it was infeasible. I would've had to set up specific functionality on each of their computers. It seems the best workaround would be to establish the script on the server to which you would like to copy your files, and then move them from your local drive to that location in a more traditional means. That would mean a file server with CGI-exec capabilities, though, which our server did not possess.



I'd guess that you are on windows and that you have I: mapped to a share such as \server2files ...

If so, that's your problem. These mappings are only avaialble to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\serversharefolderfile.ext', also remember that the IUSR account will need access to these shares/folders/files

Friday, May 28, 2021

Getting the response of another server using include is disabled by default in the php.ini for security reasons, most likely you won’t be able to use it. Use file_get_contents instead.

In your file.php you can make a json response using your data and echo it:

$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$a = "testing";

header('Content-type: application/json');
echo json_encode(
    'email' => $email,
    'name' => $name,
    'a' => $a

And in the A.php you need to parse the json string to get your data:

$data = json_decode(file_get_contents(''));
echo $data['email'], ' ', $data['name'], ' ', $data['a'];
Thursday, April 1, 2021

Dump your data out using mysqldump and then pipe that file into mysql to import the data somewhere else.

On server1:

mysqldump empData > empData.sql

On server2:

mysql < empData.sql

If you want to get fancy, you could use pipes and ssh to pipe the data directly from server1 to server2.

Thursday, April 1, 2021

distutils.dir_util.copy_tree does what you want.

Copy an entire directory tree src to a new location dst. Both src and dst must be directory names. If src is not a directory, raise DistutilsFileError. If dst does not exist, it is created with mkpath(). The end result of the copy is that every file in src is copied to dst, and directories under src are recursively copied to dst. Return the list of files that were copied or might have been copied, using their output name. The return value is unaffected by update or dry_run: it is simply the list of all files under src, with the names changed to be under dst.

(more documentation at the above url)

Sunday, August 8, 2021

It might, but any time the corresponding files in export and webroot have the same content but different modification times, you'd wind up performing an unnecessary copy operation. You'd probably get slightly smarter behavior from rsync:

rsync -pr ./export /path/to/webroot

Besides, rsync can copy files from one host to another over an SSH connection, if you ever have a need to do that. Plus, it has a zillion options you can specify to tweak its behavior - look in the man page for details.

EDIT: with respect to your clarification about what you mean by preserving permissions: you'd probably want to leave off the -p option.

Thursday, September 9, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :