php-windows Digest 19 Apr 2007 01:36:05 -0000 Issue 3199
Topics (messages 27716 through 27722):
Re: post thru fsockopen
27716 by: Joakim Ling
PHP & Javascript
27717 by: Alf Stockton
27718 by: Bill Bolte
27719 by: Mikael Grön
27720 by: Alf Stockton
27721 by: Aleksandar Vojnovic
27722 by: bedul
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
-----Original Message-----
From: James Crow [mailto:[EMAIL PROTECTED]
Sent: den 17 april 2007 18:59
To: [EMAIL PROTECTED]
Subject: Re: [PHP-WIN] post thru fsockopen
On Tuesday 17 April 2007 10:46:58 Joakim Ling wrote:
> Hi there
>
> Im tring to send a file with a php script, Im using php 5.2 on a Win
> 2003 server. At the other end I just save the file and process the
data
> and print the result, then fetch the output and write a report. But
this
> doesn't work, any one got an idea? The file never get to the other
end?
> When I do a var_export($_POST) is empty.
>
>
> This is the code I use:
> function postFile($file,$host,$path)
> {
> $remote_page = "http://".$host.$path;
> $boundary =
> "---------------------------".substr(md5(rand(0,32000)),0,10);
>
> // read the file
> $fp = @fopen($file,"r");
> if (!$fp) die ("Cannot read $file !!");
> $content_file = fread($fp,filesize($file));
> fclose($fp);
>
> // define HTTP POST DATA
> $data = "--$boundary\n".
> "Content-Disposition: form-data; name=\"file\"; filename=\"$file\"\n".
> "Content-Type: application/octet-stream\n\n$content_file".
> "--$boundary--\r\n\r\n";
>
> $msg = "POST $remote_page HTTP/1.0\n".
> "Content-Type: multipart/form-data; boundary=$boundary\n".
> "Content-Length: ".strlen($data)."\r\n\r\n";
>
> // Open socket connection ...
> $f = fsockopen($host,80, $errno, $errstr, 30);
> if ($f)
> {
>
> // Send the data
> fputs($f,$msg.$data);
>
> // retrieve the response
> $result="";
>
> while (!feof($f)) {
> $result.=fread($f,1024);
> }
>
> fclose($f);
> // write the response (if needed)
> return $result;
> } else {
> die ("Cannot connect !!!");
> }
> }
If you can use file_get_contents() with the allow_url_fopen = yes
directive in
php.ini it would be easier.
>From http://us2.php.net/manual/en/wrappers.http.php :
<?php
$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false,
$context);
?>
I have done something similar except I used the $_REQUEST variable in
the
remote script rather than doing a POST. I had just a small amount of
data to
pass so $_REQUEST worked for me.
On Windows with PHP4 I had to do some tricks to get this type of thing
to
work. On Linux with PHP5 it worked flawlessly.
Thanks,
James
--
James Crow
--
Thanks for the example. But I found the error in my script,
"Content-Disposition: form-data; name=\"file\"; filename=\"$file\"\n".
I had to do a basename($file) first of course :)
-- jocke
--- End Message ---
--- Begin Message ---
Please suggest a way to pass the value contained in a PHP variable to
Javascript.
I have $ID with a certain value in PHP and want to do a Javascript
window.location="Another.php?UID="+2;
and replace the above hardcoded 2 with the value in $ID.
--
Regards,
Alf Stockton www.stockton.co.za
This night methinks is but the daylight sick.
-- William Shakespeare, "The Merchant of Venice"
My email disclaimer is available at www.stockton.co.za/disclaimer.html
--- End Message ---
--- Begin Message ---
Google is your friend:
http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGG
L:2006-19,GGGL:en&q=javascript+querystring
-----Original Message-----
From: Alf Stockton [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 18, 2007 8:05 AM
To: php windows
Subject: [PHP-WIN] PHP & Javascript
Please suggest a way to pass the value contained in a PHP variable to
Javascript.
I have $ID with a certain value in PHP and want to do a Javascript
window.location="Another.php?UID="+2;
and replace the above hardcoded 2 with the value in $ID.
--
Regards,
Alf Stockton www.stockton.co.za
This night methinks is but the daylight sick.
-- William Shakespeare, "The Merchant of Venice"
My email disclaimer is available at www.stockton.co.za/disclaimer.html
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Google! is your friend, but I acutally enjoy typing. :)
Do something like this:
<script type="text/javascript">
window.location="another.php?UID=<?php echo
$thevariablecontainingthenumbertwo; ?>";
</script>
or something like that. :)
You know, PHP parses before the browser gets to do JavaScript stuff, so
when the browser gets the code, it'll say UID=2 ... or what ever
variable you've got stored in $thevariablecontainingthenumbertwo.
Mike
Alf Stockton skrev:
Please suggest a way to pass the value contained in a PHP variable to
Javascript.
I have $ID with a certain value in PHP and want to do a Javascript
window.location="Another.php?UID="+2;
and replace the above hardcoded 2 with the value in $ID.
--- End Message ---
--- Begin Message ---
Mikael Grön wrote:
Google! is your friend, but I acutally enjoy typing. :)
Do something like this:
<script type="text/javascript">
window.location="another.php?UID=<?php echo
$thevariablecontainingthenumbertwo; ?>";
</script>
or something like that. :)
You know, PHP parses before the browser gets to do JavaScript stuff, so
when the browser gets the code, it'll say UID=2 ... or what ever
variable you've got stored in $thevariablecontainingthenumbertwo.
Thank you Mikael.
One of my problems is getting my mind around what happens on the client
and what happens on the server. Even though I knew that PHP parses on
the server and the result of that is sent to the client where javascript
operates the solution you suggest never entered my mind.
I'll know better next time and thank you again.
--
Regards,
Alf Stockton www.stockton.co.za
She is not refined. She is not unrefined. She keeps a parrot.
-- Mark Twain
My email disclaimer is available at www.stockton.co.za/disclaimer.html
--- End Message ---
--- Begin Message ---
And don't forget to add
$thevariablecontainingthenumbertwo =
intval($thevariablecontainingthenumbertwo);
or stripslashes
Mikael Grön wrote:
Google! is your friend, but I acutally enjoy typing. :)
Do something like this:
<script type="text/javascript">
window.location="another.php?UID=<?php echo
$thevariablecontainingthenumbertwo; ?>";
</script>
or something like that. :)
You know, PHP parses before the browser gets to do JavaScript stuff,
so when the browser gets the code, it'll say UID=2 ... or what ever
variable you've got stored in $thevariablecontainingthenumbertwo.
Mike
Alf Stockton skrev:
Please suggest a way to pass the value contained in a PHP variable to
Javascript.
I have $ID with a certain value in PHP and want to do a Javascript
window.location="Another.php?UID="+2;
and replace the above hardcoded 2 with the value in $ID.
--- End Message ---
--- Begin Message ---
fyi your talk about simple javascript using PHP??
that's a lame..
u need to upgrade your skill for using AJAX
actualy google is your friend.. but what u want anyway.. u must to describe
the case not some talking like above
----- Original Message -----
From: "Mikael Grön" <[EMAIL PROTECTED]>
To: "php windows" <[EMAIL PROTECTED]>
Sent: Wednesday, April 18, 2007 10:00 PM
Subject: Re: [PHP-WIN] PHP & Javascript
> Google! is your friend, but I acutally enjoy typing. :)
>
> Do something like this:
>
> <script type="text/javascript">
> window.location="another.php?UID=<?php echo
> $thevariablecontainingthenumbertwo; ?>";
> </script>
>
> or something like that. :)
> You know, PHP parses before the browser gets to do JavaScript stuff, so
> when the browser gets the code, it'll say UID=2 ... or what ever
> variable you've got stored in $thevariablecontainingthenumbertwo.
>
> Mike
>
>
> Alf Stockton skrev:
> > Please suggest a way to pass the value contained in a PHP variable to
> > Javascript.
this line is very weird.. pass value from PHP to JS is easy.. u need to
beware about wrong statement.
but pass value from JS to PHP is a tricky things
> > I have $ID with a certain value in PHP and want to do a Javascript
> > window.location="Another.php?UID="+2;
> > and replace the above hardcoded 2 with the value in $ID.
u need AJAX.. u might try search on YAHOO-AJAX (i don't quited remember the
name.)
well it only work "well" on ie actualy.. but if you able to customize well..
opera, mozilla and soon able to accept your script.
--- End Message ---