简体   繁体   中英

Failed to Send File to another computer on the same network using PHP

We're making a Foodlist site which has an Admin that has the privilege to "Add Food" and "Edit Food" which includes giving images. But all trials to send the food image to the actual computer we're going to use as a server has failed. It'd be weird to copy the image everytime we edit something or add something.

Our site requires us to simply send a file from our computer to another in their "xampp\\htdocs\\sitepage\\images" folder. We're on the same network. Here's our code.

$my_file = 'C:\Users\ASUS\DownloadsMyFile.jpg';

/* New file name and path for this file */
$destination_file = '192.168.1.105/sitepage/images/INeedSomeRest.jpg';

/* Copy the file from source to server */
$copy = copy( $my_file, $destination_file );

/* Add notice for success/failure */
if( !$copy ) {
    echo "It didn't work.";
}
else{
    echo "WOOT! Successfully copied the file.";
}

It always gives us an error such that the browser says something like: " failed to open stream: No such file or directory in ~our php file~ "

Is there something we're doing wrong? That being said, is there another way to send a file to another computer via PHP? A Response will be greatly appreciated. Thank you in advance.

It seems I took the "copy" method of php all wrong. it seems it can only take a file from another server to your computer, and not the other way around. To the people who have the same problem as me, try to read about File Transfer Protocols. =) I appreciate all the replies. Thank you.

1) Try to use $destination_file = 'http://192.168.1.105/sitepage/images/INeedSomeRest.jpg'; (note about http:// )

2) Make sure that you CAN write to that resource (enough rights, shared properly, etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM