Save image in remote location php - php

I want to save my website images in remote location with php?
I saved my image by url with this script
file_put_contents($img, file_get_contents($orginall))
and now I need save images in another remote server.
any idea?

For that you need to have an FTP Access to that remote location.
You could make use of the ftp_put() for this.
Important Side Note : The MODE should be set to FTP_BINARY

you can try rsync with exec command:
exec('rsync -au /var/www/uploads/x.png user#000.000.000.000:/var/www/images/x.png');
but you need to setup a passwordless access to remote server from your apache user. this post might help you accomplish that

Related

Upload from local URL to server

Is it possible to send file from a local URL?
I need to upload files in php from your local url, eg I open the web page with:
www ... upload.php?url=c://...file.jpg,
from the url GET,I would get the file on the pc and would upload, without using html or anything else that I have to choose, just with the file url.
Important, it can only be this way, it will not be possible to choose the file during the upload, it will only be a POST or GET with the local url.
I researched and found nothing related, if anyone can help
I think it is impossible for server to get a client file by using the file path.
But maybe you can use JS and FileSystemobject to prepare the file, make it to streaming and post to the server.
And you must know FSO need a high security permission and may be disabled on users' browser.

Move file to specific path in PHP

I'm building a web app with MySQL/PHP/JS.
I have files in htdocs/mywebsite/foo/foo1/ path. Example:
htdocs/mywebsite/foo/foo1/image.png
I need to move these files to:
htdocs/mywebsite/foo3/image.png
Any help?
There is a rename() function in PHP that will just rename a file or will move it from one directory to another if the from and to directories are different.
<?php
rename("htdocs/mywebsite/foo/foo1/image.png",
"htdocs/mywebsite/foo3/image.png");
?>
In order to move files on a fileserver you need to use FTP (File Transfer Protocol). Programs like FileZilla could help you with that. A proper webhost should also have a FTP client on the control panel.
Using FileZilla:
Login to your webserver, simply cut and paste or drag and drop.
if you need to simple move all files from FTP using FTP tools like filezila or many other FTP software.
second from putty use mv command to move file.

PHP Open FTP XML Feed and Save On Another Server

I would kindly like to know if anyone has a simple PHP script which I can run as a cron to basically open a XML file from a URL I have (on a different server) and re-save in a directory on my own server.
The URL is a FTP URL with a username and password.
Easy:
file_put_contents(file_get_contents('ftp://user:password#remoteserver.com/file.xml'), '/path/to/new.xml');

Upload a file from one server to another server

I have to site on two different servers.
I want to upload a file www.myserver.com/thefile.txt to www.myotherserver.com/thesamefile.txt
Although the easiest way is to download the file to my computer and then upload, I would like to know if I can automate and make the server download it
You could just make the other server access the URL you wrote, www.myserver.com/thefile.txt, and publish it as www.myotherserver.com/thesamefile.txt?
If you have ssh on both servers try to use scp.
`scp file ssh_login#host:/path_to_download/
Or use php ftp_* functions.
The following code fragment should work. Just make sure that the $read_file is the url on the first server and the $write_file the location on your current server, it should not be an url but an absolute location on your server where you should be able to write.
<?php
function copyFile($read_file, $write_file)
{
file_put_contents($write_file, file_get_contents($read_file));
}
?>
You have two options:
Using php ftp support, and upload the file to another server
Create script to myotherserver.com, make post request with file contents and save the contents using php(eg: file_put_contents)

how to save uploaded file in another server?

I have tow servers for my web site. first, for database and php files. the second, for save useres' uploaded files.
So, if I uploade a file in server-1 xxx.com. how could i save it in server-2 yyy.com??
if you want two servers to be exact clones (contianing same files) you can run a rsync script after your first uplaod has completed. Its very easy and best of you don't have to specify files.
Lets say you want to transfer all files in directory /files/ to server2 in directory /files/2/ You can run this :
rsync /files/ yyy.com:~/files/2/
If you ONLY want specific files (extensions) to be synced, you can do this:
rsync /files/*.mp3 yyy.com:~/files/2/
The above will move ONLY MP3.
You can simply upload one file from server 1 to the server 2 using PHP's FTP functions.
See code example here: http://www.jonasjohn.de/snippets/php/ftp-example.htm
Use shared storage (SAN). Or SMB shares if on Windows. Or NFS if on Unix. Or scp (ssh) with public key authentication if on Unix.
An ugly way I used once was to pass via cURL and FTP commands
Of you course, you need to have access to your server-2 FTP...

Categories