Solved

wget and php

Posted on 2004-09-23
6
15,480 Views
Last Modified: 2011-08-18
Hi,
I would like to use PHP to transfer files from remote servers onto my server. I have been informed that wget is the best method to use, the only problem is, I don't know how to use it! :)

So if anyone could create a small script in php which will allow me to use wget, and save the files to a selected directory, I would be extremely grateful!
0
Comment
Question by:spikeyjames
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12131426
You could offcourse drop the wget idea an just use

<?php copy('Remotefile', 'Localfile'); ?>

But when you are realy needing to use wget you would probably have to use the exec function:
http://nl2.php.net/manual/en/function.exec.php

<?php exec('wget params');

regards

-r-
0
 
LVL 1

Author Comment

by:spikeyjames
ID: 12131497
thanks a lot.
If I use <?php copy ();?>, does it give a limit to the file size I transfer? The files that I need to move to the server are several hundred MB each. If that is not a problem, then great!
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12131535
Hmm.. that indeed might be a problem, you could/would use set_time_limit() to prevent the script from timing out, but quit a loss when you set it to low and the script cancels when you've copied about 75% of the 700mb.

I don't know wether or not the programs called with exec() continue their work when the script timeouts. You should read the manual (php.net/exec) to discover.

I have an appointment at the moment, so can't do it for you.

good luck

-r-
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:spikeyjames
ID: 12131665
i remember reading somewhere that it's the same with wget. So I think that copy() would do the job just as well.

Now my next problem is the code. How do I set the timeout limit? The server's connection is 10mb, and I would assume that the largest files I will be transfering will be around 750~800MB. So that's about 800 seconds, so say 1000 seconds to be safe.

I realise you're busy so don't worry, there's no rush. But if you could help me expand this code, I would appreciate it:

<?php
$remotefile = $_POST['remotefile'];
$localfile = "/files";
copy('$remotefile', '$localfile', ?TIMELIMIT?);
if (?COPY IS SUCCESSFUL?) {echo "Done";} else {echo "Error";}
?>
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 12131690
<?php
set_time_limit(1500); //1500 secs to be sure.

$remotefile = $_POST['remotefile'];

$localfile = "/files/".basename($remotefile); //basename() returns the movie.avi from www.domain.com/dir/movie.avi

if(copy($remotefile, $localfile)) {
  echo "Done";
}
else {
  echo "Error";
}
?>

-r-
0
 
LVL 1

Author Comment

by:spikeyjames
ID: 12131710
THANK YOU! You have been really helpful!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now