php-general Digest 16 Jan 2012 01:26:07 -0000 Issue 7651

Topics (messages 316298 through 316300):

Re: php://input
        316298 by: Frank Arensmeier

Measuring CPU time
        316299 by: Tim Streater

Numeric help needed
        316300 by: Christopher J Payne

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
15 jan 2012 kl. 06.18 skrev Adam Tong:

> Hi,
> 
> I am trying to read variables from input method.
> I am using this tuorial:
> http://www.lornajane.net/posts/2008/Accessing-Incoming-PUT-Data-from-PHP.
> Here is my code:
> <?php
> if($_SERVER['REQUEST_METHOD'] == 'GET') {
>    echo "this is a get request\n";
>    echo $_GET['fruit']." is the fruit\n";
>    echo "I want ".$_GET['quantity']." of them\n\n";
> } elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
>    echo "this is a put request\n";
>    parse_str(file_get_contents("php://input"),$post_vars);
>    echo $post_vars['fruit']." is the fruit\n";
>    echo "I want ".$post_vars['quantity']." of them\n\n";
> }
> ?>
> 
> I am using the firefox extension  "poster" to run this example. GET
> works fine but when using PUT, file_get_contents("php://input")
> returns an empty string.
> 
> I found a bug related to this: https://bugs.php.net/bug.php?id=51592
> 
> I am using xampp on win7 (
> + Apache 2.2.17
>  + MySQL 5.5.8 (Community Server)
>  + PHP 5.3.5 (VC6 X86 32bit) + PEAR)
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Hi Adam.

Although I've never worked with PUT/DELETE requests, here are my thoughts.

1) According to the manual, file_get_contents only allows URL's as filenames if 
"fopen wrappers" are enabled. Make sure that this is the case (have a look at 
the settings in your php ini file). Do you get any data when changing 
'file_get_contents' to e.g. (as found here: 
http://php.net/manual/en/features.file-upload.put-method.php)?

<?php
/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");

/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");

/* Read the data 1 KB at a time
   and write to the file */
while ($data = fread($putdata, 1024))
  fwrite($fp, $data);

/* Close the streams */
fclose($fp);
fclose($putdata);
?>

2) Have a look in your Appache log files and make sure the client is actually 
making a valid PUT request.

/frank


--- End Message ---
--- Begin Message ---
I haven't found a function to allow me to see elapsed CPU time to date in a 
function. Am I right in thinking none such exists?

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
Hi everyone,

 

I am having a hard time with a numerical problem.

 

I need to round some numbers up and I've tried $round($number) and it
doesn't work so I'm misunderstanding something.

 

For example, if a user inputs 685000 I need it to round up to 690000 or if
they input 149560 I need it to round up to 150000.  What is the correct way
to do this as everything I have tried doesn't seem to affect the user
inputted figure at all.

 

Anyway help would REALLY be appreciated, I'm sure it's really simple but for
the life of me I'm stumped on why it's not working.

 

Chris


--- End Message ---

Reply via email to