Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-17-2007, 08:29 PM Wget in PHP
Novice Talker

Posts: 6
Trades: 0
Hey Guys,

I'm hoping to have a form where someone can enter a url to download a file only my net connection has access to, then it will use php/wget/curl to download that file and save it on the webserver.

E.g, they enter www.blah.com/pic.jpg and it will download and save to /home/www/pics/pic.jpg.

Can someone possibly help me code this as I'm a complete noob. So far I've got one form that gets their information they are after, which then loads up a second page which is meant to download the file but not working very well.

Help Please
shynx is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-18-2007, 01:40 AM Re: Wget in PHP
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Maybe sharing the code you have which has a problem would be helpful?
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-18-2007, 03:40 AM Re: Wget in PHP
Novice Talker

Posts: 6
Trades: 0
Well yes, I can see how that would work. I can download the file but I can't make it save as the original filename. Must be something easy I am missing.

Quote:
Originally Posted by br.html View Post
<form action="wget.php" method="POST">
<font face="arial" size=3 color="336666">Enter Battlerecorder file here: <input type="text" name="brfile">
<input type="submit" value="Download">
</form>
Quote:
Originally Posted by wget.php View Post
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP
$brfile = $_POST['brfile'];
print ($brfile);
?>

</head>

<?
file_put_contents('/opt/lampp/htdocs/bf2/battlerecorder/($brfile)',
file_get_contents($brfile));
?>
shynx is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 03:40 AM Re: Wget in PHP
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
1. Make a form with two fields: URL and local file name
2. When a form is submitted do exec("wget -O{$local_file_name} \"{$url}\" > /dev/null &") to execute wget in background.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-18-2007, 03:42 AM Re: Wget in PHP
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Or "wget -o $url" to keep the original file name. I recommend you not to use file_get_contents for this because the user can give you url to some large file which will take more time to download than the script is executed.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-18-2007, 04:12 AM Re: Wget in PHP
Novice Talker

Posts: 6
Trades: 0
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP

$brfile = $_POST['brfile'];
$localfile = $_POST['localfile'];
print ($brfile);

?>

</head>
<?php
do exec("wget -O{$localfile} \"{$brfile}\" > /dev/null &")
?>


Parse error: syntax error, unexpected $end, expecting T_WHILE in wget.php on line 18

Sorry guys, thats the error I get. Remember, complete noob. I also added localfile to br.html to get that part working. Also tried it using wget -o and still didn't work.
shynx is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 04:37 AM Re: Wget in PHP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
do exec("wget -O{$localfile} \"{$brfile}\" > /dev/null &");

notice the ; at the end
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 10-18-2007, 06:36 AM Re: Wget in PHP
Novice Talker

Posts: 6
Trades: 0
Quote:
Originally Posted by solomongaby View Post
do exec("wget -O{$localfile} \"{$brfile}\" > /dev/null &");

notice the ; at the end
Parse error: syntax error, unexpected ';', expecting T_WHILE in wget.php on line 17

Weird
shynx is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 07:20 AM Re: Wget in PHP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
sorry my bad ... remove the "do" :
exec("wget -O{$localfile} \"{$brfile}\" > /dev/null &");
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 10-18-2007, 08:23 AM Re: Wget in PHP
Novice Talker

Posts: 6
Trades: 0
Thats awesome, thanks guys. You guys rock... thanks very much for help

Last edited by shynx; 10-18-2007 at 08:30 AM..
shynx is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 08:53 AM Re: Wget in PHP
Novice Talker

Posts: 6
Trades: 0
How do you save it to a particular place?
I thought this would work...

exec("wget -O /tmp/{$brfile} \"{$localfile}\" > /dev/null &");

but nothing is saved, though no errors in script. Unless its not downloading any files at all? I can't find any files otherwise :/

Last edited by shynx; 10-18-2007 at 08:58 AM.. Reason: FIXED!
shynx is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 09:56 AM Re: Wget in PHP
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
iy should be saved in the account root ... but remove the /tmp thing
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to Wget in PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41627 seconds with 12 queries