Reputation: 31
Folks
I have an image at some server (SOURCE) i.e. http://stagging-school-images.s3.amazonaws.com/2274928daf974332ed4e69fddc7a342e.jpg
Now I want to upload it to somewhere else (DESTINATION) i.e. example.mysite.com/receiveImage.php
First, I am copying image from source to my local server and then uploading it to destination. It's perfectly working but taking too much time as it copy the image and then uploads... I want to make it more simple and optimized by directly uploading image from source URL to destination URL.
Is there a way to handle this ?
I am using php/cURL to handle my current functionality.
Any help would be very much appreciated.
Cheers !!
Upvotes: 1
Views: 646
Reputation: 7790
If example.mysite.com/receiveImage.php is your own service, then you may
Otherwise it's impossible by means of HTTP.
However, there are some ways to increase files uploading speed a little:
If files are huge, you may use two threads: one for downloading (it will store all downloaded data to some buffer) and one for uploading (it will get all available data from buffer and upload it to site). As far as I know, this can't be done easily with PHP, because multi-threading is currently not supported yet.
If there are too many files, you may use many threads / processes, which will do download/upload simultaneously.
By the way, these means do not eliminate double traffic for your intermediate service.
Upvotes: 2
Reputation: 522499
The only way to transfer the image directly from source to destination is to initiate the transfer from either the source or the destination. You can't magically beam the data between these two locations without them talking to each other directly. If you can SSH login to your mysite.com
server you could download the image directly from there. You could also write a script that runs on mysite.com
and directly downloads the image from the source.
If that's not possible, the best alternative may be to play around with fread
/fwrite
instead of curl. This should allow you to read a little bit from the source, then directly upload that bit to the destination so download and upload can work in parallel. For huge files this should make a real difference, for small files on a decent connection it probably won't.
Upvotes: 0
Reputation: 1980
create two textfield one url, other filename in php, use : uploadDir is path to your file directory ;)
copy($url, $uploadDir.'/'.$fileName);
Upvotes: -1
Reputation: 799210
One of the services may have a form somewhere that will allow you to specify a URL to receive from/send to, but there is no generic HTTP mechanism for doing so.
Upvotes: 0