php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #10307 PHP refusing to get temporary file name from an HTTP PUT request.
Submitted: 2001-04-12 13:17 UTC Modified: 2002-12-02 00:00 UTC
Votes:19
Avg. Score:4.8 ± 0.4
Reproduced:17 of 17 (100.0%)
Same Version:5 (29.4%)
Same OS:2 (11.8%)
From: excalibur at hub dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.1 OS: freebsd 4.2
Private report: No CVE-ID: None
 [2001-04-12 13:17 UTC] excalibur at hub dot org
I am using PHP 4.04pl1 on a FreeBSD 4.2 based system with Apache 1.3.19. I have a page that is "accepting" HTTP PUT requests and is supposed to save the file in a designated area, however PHP is not picking up the temporary filename while the script runs. All other variables required are set, but not $PHP_PUT_FILENAME. I have tried all recommendations in the docs, mailing list and IRC channels. None have worked. I do notice that the protocol level is HTTP 1.0 PUT not HTTP 1.1 PUT, I have not been able to determine if that is the issue.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-19 12:14 UTC] jan@php.net
perhaps you can add a sample script for other to reproduce the misbehaviour.
 [2001-05-23 10:04 UTC] excalibur at hub dot org
This is a copy of all the versions we tried, none of them worked in the slightest.

<?php

//  copy($PHP_PUT_FILENAME,$DOCUMENT_ROOT.$REQUEST_URI);
 $fp = fopen("/home/vhosts/farelist.com/www/update/log.txt","w+");
 if(!copy ($PHP_PUT_FILENAME, "/home/vhosts/farelist.com/www/update/test.txt")) {
   fwrite($fp, "\n\ncopy failed\n\n");
 } else {
   fwrite($fp, "\n\ncopy successful\n\n");
 }

 $temp="PHP_PUT_FILENAME: $PHP_PUT_FILENAME\n";
 $vars = get_defined_vars();
 foreach ($vars as $test => $value) {
  if (is_array($value)) {
   foreach ($value as $subtest => $subvalue) {
    $temp .= "$subtest: $subvalue\n";
   }
  } else {
   $temp .= "$test: $value\n";
  }
 }
 fwrite($fp, $temp);
 $temp="DOCUMENT_ROOT: $DOCUMENT_ROOT\n";
 fwrite($fp, $temp);
 $temp="REQUEST_URI: $REQUEST_URI\n";
 fwrite($fp, $temp);
 fclose($fp);
?>
 [2002-02-11 18:33 UTC] steve dot venable at lmco dot com
Not sure if problem is documentation or PHP bug.  Excalibur's example to dump all variables duplicates my results, PHP doesn't provide temporary filename for PUT data.  Documentation says "$PHP_PUT_FILENAME" and example uses "$PHP_UPLOADED_FILE_NAME" neither of which are defined.  It does work with CGI script as data to 'stdin' but how do you read this in PHP?  Platform is Solaris 8 with PHP 4.1 in Apache 1.3.22
 [2002-06-11 16:23 UTC] ja at certiflexdimension dot com
I can replicate the same issue with the sample code in the manual.

copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI);

I'm running Apache 1.3.24 with PHP 4.2.0, on RedHat 7.1... I'm guessing this either got ignored, or the variable got removed.  The header that is returned just says:

Unable to open '' for reading:  No such file or directory in <script name> on line <line no>.
 [2002-06-14 10:28 UTC] shiflett@php.net
Can any of you who are having this problem please provide an example of the HTML form you are supporting with the PHP code you've provided? Meaning, what is the markup and/or PHP code for the page that generates the file upload?

I think I have an idea on this.
 [2002-07-14 19:15 UTC] briand at tps-eoltp dot com
I have duplicated this problem with PHP 4.2.1, on a Linux Mandrake system
with an Apache 1.3 server.  However, instead of a browser, I am
using the W3C libbwww sample program, put.c 
(http://www.w3.org/Library/Examples/put.c).  This is about as 
"official" a PUT command as you can get.

For a server script, I have one that is about as simple as 
you can get.

<?php
#copy($PHP_UPLOADED_FILE_NAME,"uploaded_file");
print "$PHP_UPLOADED_FILE_NAME";
?>

I've tried many variations, printing out $_POST and $_FILES, 
and other variables, all with the same empty results.
Any new ideas?
 [2002-07-15 03:22 UTC] t dot jago at its dot uq dot edu dot au
I am using FreeBSD 4.6 and mod_php4-4.2.1_2.
I am using curl to send the file.
curl -T /kernel http://server/test.dat

Interesting thing is that the PHP code is executed and terminated BEFORE the file has completed uploading. Weird.
 [2002-08-13 22:43 UTC] kalowsky@php.net
updating version as per user comments.
 [2002-08-25 12:40 UTC] vvs_php at nsrd dot sinp dot msu dot ru
PUT method is used for publishing from HTML editors.
But apache brings the data to the script to the stdin stream.
So, PHP does not accept any data. And, also, does not set up 
any variable on that score.
 [2002-08-25 19:57 UTC] wez@php.net
Sounds like the data is ending up coming from stdin;
try the following code:

$data = fopen("php://stdin", "rb");
$destfile = fopen("file_to_overwrite", "wb");
while(!feof($data)) {
   $chunk = fread($data, 4096);
   fwrite($destfile, $chunk);
}
fclose($destfile);
fclose($data);

This doesn't explain why it doesn't behave as documented,
but should be enough to get you going.
 [2002-08-25 20:14 UTC] wez@php.net
Making this a Documentation Problem; I can't find any code
that sets PHP_UPLOADED_FILE_NAME, PHP_PUT_FILENAME or
other variations, so it seems that the docs at
http://www.php.net/manual/en/features.file-upload.put-method.php
are just plain wrong.
However, it does seem that fopen("php://stdin", "rb") will
allow access to that data (but I haven't tried to verify this).

 [2002-08-26 00:40 UTC] alan at akbkhome dot com
I couldnt get PUT to work like that, looks like this patch will solve it.

http://marc.theaimsgroup.com/?l=php-dev&m=102983806024466&w=2

(read the following responsed for a bit more detail on why php cant read PUT at present)

regards
Alan
 [2002-12-02 00:00 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Provided example of using php://stdin and note re: Changed behavior from PHP3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC