Login   Register  
PHP Classes
elePHPant
Icontem

download file with post

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  download file with post  >  (Un) Subscribe thread alerts  
Subject:download file with post
Summary:download a xls file with post
Messages:6
Author:Fernando
Date:2006-05-16 06:21:55
Update:2006-05-17 07:48:48
 

  1. download file with post   Reply  
Picture of Fernando
Fernando
2006-05-16 06:21:55
Hi:
I'm traying to get a xls file through post, i made changes to a vars $url,$arguments["PostValues"] and $arguments["Referer"] and it's working fine(gracias Manuel :=) ), but i need to download the file so need your help, tell me how can i convert response o how get response as a file.

thank you!

those are response headers and response body(a part of it)

Response headers:
http/1.1 200 ok:
cache-control: must-revalidate, post-check=0,pre-check=0
pragma: public
content-type: application/vnd.ms-excel
expires: 0
server: Microsoft-IIS/6.0
x-powered-by: PHP/4.3.10
x-powered-by: ASP.NET
content-disposition: attachment; filename=precios Aji.xls
microsoftofficewebserver: 5.0_Pub
date: Tue, 16 May 2006 05:56:52 GMT
connection: close

Response body:
╨╧рб▒с>■  )■   ■   *                                                                                                                                                                                                                                                                                                                                                                                                                                                 l ╔
PreciosAji=╝%r8X"1╚ РArial1╚ РArial1╚ РArial1╚ РArial1╚ РArial1╚ РArial1▄ РArial1РArialрї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ рї  └ р └ р └ р HМ р HЙ УА Тт8            ААААААААА└└└АААЩЩ Щ3f  ╠╠  ff ААf╠╠╠ А      ААААА ╠ ╠  ╠ ╠  ЩЩ╠  Щ╠╠Щ  ╠Щ3f 3╠╠Щ╠ ╠ Щ fffЩЦЦЦ3f3Щf333Щ3Щ3f33Щ333ЕБ
PreciosAji
l ╔*+ВБ┴б"dXXр?р?
Y
XP┌ltimo Precio pagado por los distintos poderes compradores para el producto: AjiRegiєn ProvinciaPoder Comprador
FechaVariedadCalidad
Unidad MedidaMoneda
Precio Mсximo 
Precio Mэnimo
 Precio Com·n
IV
Elqui$Feria Mayorista Las Palmeras
2001-11-02 AmericanoPrimera Peso 

IV
Elqui$Feria Mayorista Las Palmeras
2005-12-19 AmericanoPrimera Kilo Pesoрu@ y@
y@
IV
Elqui$Feria Mayorista Las Palmeras
2005-10-19 AmericanoSegunda Kilo Peso@@ └В@
└В@
IV
Elqui$Feria Mayorista Las Palmeras
2001-12-14CristalPrimera Peso 

IV
Elqui$Feria Mayorista Las Palmeras
2002-08-21CristalPrimera
Caja 30 Kilos Peso Ь@  Ь@
 Ь@
IV
Elqui$Feria Mayorista Las Palmeras
2002-12-04CristalPrimera Kilo Peso└r@ y@
рu@
IV
Elqui$Feria Mayorista Las Palmeras
2002-11-07CristalSegunda Peso 

IV
Elqui$ Feria Mayorista Las Palmeras 
2002-08-21 Cristal Segunda 
Caja 30 Kilos Peso └Т@ └Т@
└Т@

IV
Elqui$
Feria Mayorista Las Palmeras

2002-11-21
Cristal
Segunda
Kilo
Peso
y@
y@

y@
IV
Elqui$ Feria Mayorista Las Palmeras 
2002-09-02 Cristal Tercera Kilo Peso @П@ @П@
@П@
IV
Elqui$ Feria Mayorista Las Palmeras 
2002-12-30 Cristal America Primera Kilo Peso `И@ Й@
Й@

IV

Elqui$
Feria Mayorista Las Palmeras

2002-12-23
Cristal America
Segunda
Kilo
Peso
@@
@@
@@
IV
Elqui$Feria Mayorista Las Palmeras
2002-11-25InfiernoPrimera Kilo Pesoy@ y@
y@
IV
Elqui$Feria Mayorista Las Palmeras
2005-04-20Sin EspecificaPrimera Kilo Pesoy@ @@
 |@
IV
Elqui$Feria Mayorista Las Palmeras
2006-04-21Sin EspecificarPrimera Kilo Peso└r@ └r@
└r@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-06-22 Kilo Peso└В@ Й@
рЕ@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-05-25Primera Kilo Pesoi@ i@
i@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-11-02 AmericanoPrimera Peso 

IVLimarэ)!Feria Mayorista El Agro de Limarэ
2006-05-10 AmericanoPrimera
Caja 30 Kilos PesoX╗@ X╗@
X╗@
IVLimarэ)!Feria Mayorista El Agro de Limari
2005-08-12 AmericanoPrimera Kilo Peso333333є? 333333є?
333333є?
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-06-20 AmericanoPrimera Kilo Peso@П@ └Т@
@П@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-12-14CRISTALPrimera Peso 

IVLimarэ)!Feria Mayorista El Agro de Limari
2002-12-04CristalPrimera
Caja 30 Kilos Pesop╖@ p╖@
p╖@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-03-21CRISTALPrimera
Caja 30 Kilos PesoФ▒@ Ф▒@
Ф▒@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2002-11-07CRISTALPrimera Kilo Pesoрu@ рu@
рu@
IVLimarэ)!Feria Mayorista El Agro de Limari
2002-04-22CristalPrimera Kilo PesoАQ@ АQ@
АQ@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-12-28CRISTALPrimera Kilo Pesoy@ y@
y@
IVLimarэ)!Feria Mayorista El Agro de Limari
2001-01-28CristalPrimera Kilo PesoАf@ Аf@
Аf@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2001-01-26CRISTALPrimera Kilo Peso└b@ └b@
└b@
IVLimarэ)!Feria Mayorista El Agro de Limarэ
2002-11-07CRISTALSegunda Peso 

IV Limarэ) !Feria Mayorista El Agro de Limari 
2002-11-21 Cristal Segunda 


  2. Re: download file with post   Reply  
Picture of Manuel Lemos
Manuel Lemos
2006-05-17 02:15:32 - In reply to message 1 from Fernando
I am not sure what is the difficulty. If you want to download a file and store it in a local file, just keep reading the response body with the function ReadReplyBody and write the data to your local file.

  3. Re: download file with post   Reply  
Picture of Fernando
Fernando
2006-05-17 04:57:28 - In reply to message 2 from Manuel Lemos
Ok thanks for help me, i made this code:

$error=$http->ReadReplyBody($body,1000);
if($error!=""|| strlen($body)==0)
break;
$gestor = fopen("J:\precios Aji.xls", "w");
fwrite($gestor, $body);
fclose($gestor);

But xls format is wrong, the file created shows a book with rows like this:

2002-04-15ICristalIPrimera IKilo IPesoI@o@I

As you can see, rows are not divided by columns
2002-04-15,Cristal,Primera,etc..

I really appreciate your help

  4. Re: download file with post   Reply  
Picture of Manuel Lemos
Manuel Lemos
2006-05-17 05:20:49 - In reply to message 3 from Fernando
You need to include that code in a loop so you can copy the whole file, not just the first 1000 bytes.

Also you need to use the mode "wb" when writing to binary files, or else you file may become corrupted.

  5. Re: download file with post   Reply  
Picture of Fernando
Fernando
2006-05-17 07:41:49 - In reply to message 4 from Manuel Lemos
GOTCHA!!!
ok, i fixed my code, thanks to MANUEL LEMOS (gracias loco, te pasaste de wena onda!!)
so to get a xml file through a post form i made some changes to test_http_post.php, file
included with "http protocol client class",

vars changed:

$url // giving site url
$arguments["PostValues"] // pairs variable/value
$arguments["Referer"] // request page

and code changes in the response section, replacing this:

echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n";
for(;;)
{
$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
echo HtmlSpecialChars($body);
}
echo "</PRE>\n";
flush();

to this:

echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n";
$bodyx=""; // initializing body
for(;;)
{
$error=$http->ReadReplyBody($body,100000);
if($error!=""
|| strlen($body)==0)
break;
$bodyx.=$body; // adding new parts from loop
}
$gestor = fopen("J:\precios Aji.xls", "wb"); // opening or creating file with write and binary options
fwrite($gestor, $bodyx); // writing complete body
fclose($gestor); // closing file
echo "</PRE>\n";
flush();

that's all
chao pescao

  6. update, fe de erratas. Re: download file with post   Reply  
Picture of Fernando
Fernando
2006-05-17 07:48:48 - In reply to message 5 from Fernando
update, fe de erratas.

change "...to get a xml file through..." to "...to get a xls file through..." on last reply....oops...jeje ;-), sorry
bye, chao