php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46485 Problem uploading a file
Submitted: 2008-11-04 21:35 UTC Modified: 2008-11-05 17:12 UTC
From: nyaka at nyaka dot com Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 5.2.6 OS: Solaris 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nyaka at nyaka dot com
New email:
PHP Version: OS:

 

 [2008-11-04 21:35 UTC] nyaka at nyaka dot com
Description:
------------
I'm trying to upload a file with PHP 5.2.6 and Apache 2.2.9 from a custom application. It worked for me previously with Apache 1.3 and PHP 4.3.

I also tried to use PHP 5.2.7RC3-dev (cli) (built: Nov  4 2008 20:43:51). Same results.

Reproduce code:
---------------
<?php

error_log(print_r($_FILES, TRUE));

?>

Expected result:
----------------
I expect the file to be uploaded and $_FILES array to contain correct data about that file and not an error message.

Actual result:
--------------
This is from the apache error log:

Array
(
    [wav] => Array
        (
            [name] => msg-94_48972.wav
            [type] => 
            [tmp_name] => 
            [error] => 3
            [size] => 0
        )

)

This is trace of httpd with truss:

.......
8469:   read(23, " P O S T   / v o i c e m".., 8000)    = 4344
8469:   stat64("/share/web/snom/voicemail.php", 0x08047880) = 0
.......
8469:   time()                                          = 1225822869
8469:   resolvepath("/tmp", "/tmp", 1024)               = 4
8469:   getpid()                                        = 8469 [8463]
8469:   lstat64("/tmp/phpjFaOIq", 0x08044800)           Err#2 ENOENT
8469:   open("/tmp/phpjFaOIq", O_RDWR|O_CREAT|O_EXCL, 0600) = 24
8469:   write(24, " R I F F92 6\0\0 W A V E".., 5119)   = 5119
8469:   write(24, " nDCB895EA04 69A1C I n '".., 5119)   = 5119
8469:   read(23, " nD504 H8EE3C8 rCB\0B691".., 8000)    = 2346
8469:   write(24, " 2C4E215B9 aD6 <E6 J aD9".., 3779)   = 3779
8469:   close(24)                                       = 0
8469:   unlink("/tmp/phpjFaOIq")                        = 0
.......
8469:   resolvepath("/share/web/snom/voicemail.php", "/share/web/snom/voicemail.php", 1024) = 29
8469:   open("/share/web/snom/voicemail.php", O_RDONLY) = 25
.......

I can see here that the temporary file is actually created and the data is written to it. But after the file is closed an unlink is executed. 

I can provide TCP dump if necessary.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-04 21:45 UTC] lbarnaud@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

> [error] => 3

On error, the POST handler deletes the temporary file.
Please see http://www.php.net/manual/en/features.file-upload.php
 [2008-11-04 21:53 UTC] nyaka at nyaka dot com
I understand that POST handler deletes temporary file, but should it delete if AFTER the actual php script is executed? The temporary file cannot be accessed from the php script. It is visible from the trace I provided and from dump of $_FILES variable.
 [2008-11-04 22:01 UTC] lbarnaud@php.net
On error the temp file is deleted before the PHP script is executed.
When no error, the temp file is deleted after the PHP script is executed.

Is this not what happens for you ?
 [2008-11-04 22:19 UTC] nyaka at nyaka dot com
Yes, it is exactly what happened - some part of your code thinks that there is an error. So to summarize:
1. Custom application sends the file.
2. TCP dump shows the file is transferred.
3. Trace shows that the temporary file is created and data written to it.
4. PHP deletes the temporary file.
5. PHP reports error 3 - (partial upload).

As I said, absolutely the same scenario works with previous versions of Apache and PHP. So the file was transferred; why does PHP complain?
 [2008-11-04 22:49 UTC] lbarnaud@php.net
The error code is set when the POST handler did not found the final boundary in the client's input. This may happen when the boundary is effectively missing, or e.g. when the Content-Length is incorrect.
 [2008-11-05 01:34 UTC] nyaka at nyaka dot com
I can see the correct boundary at the end of the packet in the TCP dump.
 [2008-11-05 01:57 UTC] lbarnaud@php.net
Could you please send a TCP dump ?
 [2008-11-05 14:38 UTC] nyaka at nyaka dot com
I've sent the dump to your email.
 [2008-11-05 16:48 UTC] lbarnaud@php.net
Thanks. The closing boundary is missing the "--" prefix (the last boundary must be prefixed *and* suffixed with "--").
 [2008-11-05 16:55 UTC] nyaka at nyaka dot com
That's what I see there...
But in any case, how come the same upload perfectly work with PHP 4?
 [2008-11-05 17:12 UTC] lbarnaud@php.net
Probably a bug in PHP 4 that has been fixed in PHP5.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 18:01:30 2024 UTC