Page 1 of 1

Downloading From Curl/Wget

Posted: Mon Nov 05, 2007 1:31 am
by phpFrk
O i posted in another thread about sending data to PHP from POST method. cURL did the job :)

viewtopic.php?t=75660&sid=bece4003a9b1d ... d0198fa589



What im doing is, using the batch to create file...then Uploading it one the server through POST form so the file can be stored and editted with the information i need. Ive Got it working till here, it uploads and edits the file perfectly But what i want to do next is that as the POST DATA is sent and processed i want to Download the UPDATED file back on my PC using the ID of file Generated on the same page.

TO achieve this i added a redirect link the the download page at the end of DOUPLOAD.php i added this line:

Code: Select all

header("Location: localhost/download.php/$id/$filename");
But curl doesnt automatically download the file. Is there anyway to make it download from the Redirect Link at the end of php file after sending the POST Data/File ? Im trying to Download of the same page (DOUPLOAD.php) as it includes the ID generated for the upoaded file. (if thr is any other way to send the Unique Id generated by doupload.php to the batch thn please let me know)

Any help would be greatly appreciated.

Thank you

PHPfrk

Posted: Mon Nov 05, 2007 3:54 am
by aaronhall
I'm lazy and didn't feel like deciphering your entire post, but make sure that nothing is being sent to the browser, including whitespace but excluding other headers, before the header() line. Always use fully qualified URLs in Location headers; for this, stick http:// in front of "localhost".

Posted: Mon Nov 05, 2007 6:09 am
by phpFrk
thanks for the reply

Since its a redirect i had to use -L

In the batch i have this to POST:

Code: Select all

curl  -F "file=@%%G.torrent"  http://localhost/doupload.php
I changed it to this:

Code: Select all

curl  -F "file=@%%G.torrent" -L  http://localhost/doupload.php

But this will just print the content of the file on the screen so i changed it to this:

Code: Select all

curl  -F "file=@%%G.torrent" -L -O  http://localhost/doupload.php
But this saves the file with the name of doupload.php. I tried adding "filename.txt" infont of -O but thn it will give this error and it will print the whole file on screen rather thn saving:
curl: Remote file name has no length!

Please Help

Thank you

PHPfrk

Posted: Mon Nov 05, 2007 12:59 pm
by JessicaW
phpFrk, your example with
curl -l
works fine for me

Posted: Mon Nov 05, 2007 6:57 pm
by phpFrk
Thanks for the reply jessicaW.

Code: Select all

curl  -F "file=@%%G.torrent" -L  http://localhost/doupload.php
Yes it works with -L ^^ But it doesnt save the file it just prints the content on screen.

to save the file i have to use - O like this:

Code: Select all

curl  -F "file=@%%G.torrent" -L -O  http://localhost/doupload.php
but this ^^ saves the file with the name of dupload.php (which is the name of page we have the redirect link on). If i use -O "filenameiwant.txt" it will give the error i wrote in my last post.

I can add Rename at the end, which works fine. Just want to know if it can be saved with the name i want rather thn renaming it once its saved.

Thanks

PHPFrk