is there a way to copy file between server using php ?
but still make it a live*copy still running* when we close our browser ?
since i need to download some manga, but it seem the manga server running slow, and i want download the manga from my server. of course i no need to wait until my server copy manga finished.
thanks,
im not understanding....do you want to get the image with the php or what?
i want to copy file using php. and between server,
let see, if there is www.google.com/manga.zip and i want to copy this file to my site www.mysite.com/manga.zip.
but i don't want to wait until finished the copy to close my browser.
and is there someone now, what criteria to make a file can downloadable with resume and multiple download ?
thanks,
| Philip wrote: |
i want to copy file using php. and between server,
let see, if there is www.google.com/manga.zip and i want to copy this file to my site www.mysite.com/manga.zip.
but i don't want to wait until finished the copy to close my browser.
and is there someone now, what criteria to make a file can downloadable with resume and multiple download ? |
Use CURL in a cronjob to copy the file(s), getting the info from a database (or a text file -- pay attention to file locking) written by a web page.
... or you can try to do that directly from the web page with Process Control Functions ... can't help you there.
er..... sorry, but how can i use this CURL function ??
thanks ^_^"
try this: http://sf.net/projects/phtp
it was last updated long ago, but it works great. and I'm currently working on a 3.0 version
| Philip wrote: |
| er..... sorry, but how can i use this CURL function ?? |
I changed an example from the manual a little bit to deal with files ...
This code needs error-checking!
| Code: |
<?php
################
## NOT TESTED ##
################
// create a new CURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/manga.zip");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
set_time_limit(300); # 5 minutes for PHP
curl_setopt($ch, CURLOPT_TIMEOUT, 300); # and also for CURL
$outfile = fopen('/mysite.com/manga.zip', 'wb');
curl_setopt($ch, CURLOPT_FILE, $outfile);
// grab file from URL
curl_exec($ch);
fclose($outfile);
// close CURL resource, and free up system resources
curl_close($ch);
### As this is meant to be run from cron,
### it doesn't need to output anything.
### It might be a good idea to mail yourself
### at the end though (or in case of errors)
mail('yourself@example.com', 'cron job with CURL completed', '(empty body)');
?> |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); <-- what is this for ?
anyway, it is work ^_^
thanks,
thanks for clearing that up phillip... i now see that someone else has already gotten around to helping you with your problem.. good luck with that stuff!
| coreymanshack wrote: |
| thanks for clearing that up phillip... i now see that someone else has already gotten around to helping you with your problem.. good luck with that stuff! |
uhm, you see, i have ended up my day with php, but it seem still amateur about it hehe ^_^"
| Philip wrote: |
| curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); <-- what is this for ? |
from the manual page for curl_setopt()
| Quote: |
| TRUE to return the raw output when CURLOPT_RETURNTRANSFER is used. |
I used CURLOPT_RETURNTRANSFER to stop the file from being sent to the browser; I'm not really sure CURLOPT_BINARYTRANSFER is needed, but I guess it won't break the script if it isn't
Anyway, I put that in because the file download should not have bytes interpreted ("\r\n" converted to "\n", "\0" stripped at end of file, ...). You are free to try it without that option and verify if it works.
i made a function like this,
but it seem my browser still need to wait until the copy finished. -_-"
| Code: |
function download_pretending($url,$user_agent) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
set_time_limit(3000); # 5 minutes for PHP
curl_setopt($ch, CURLOPT_TIMEOUT, 3000); # and also for CURL
$result =base64_encode(curl_exec ($ch));
curl_close ($ch);
if(!$handle = fopen(basename($url).".htm", 'w+'))
{
echo "Cannot open file ".basename($url).".htm";
exit;
}
if (fwrite($handle, $result) === FALSE) {
echo "Cannot write to file ".basename($url).".htm";
exit;
}
echo basename($url).".htm";
fclose($handle);
}
|
.. thats why its supposed to be run through a cron job. cron jobs are executed by the computer which your site is on and thus do not need your browser' presence, and can download without you executing the script.
then, how can i set this to cron job ?
thanks,