|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9298 HTTP File upload, Content-Type header is stored at the beginning of the file
Submitted: 2001-02-16 10:34 UTC Modified: 2001-02-16 11:03 UTC
From: martinw at bluecho dot com Assigned:
Status: Closed Package: HTTP related
PHP Version: 4.0.4pl1 OS: RedHat Linux 7.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: martinw at bluecho dot com
New email:
PHP Version: OS:


 [2001-02-16 10:34 UTC] martinw at bluecho dot com
For an example, using the following form

<title>Upload Test</title>
<form action="uploadtest.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedfile">
<input type="submit" value="Upload">

and uploading a file, gives me a variable $uploadedfile with the name of the temp. file on the server.  This file will have something like:

Content-Type: application/octet-stream

Content-Type: image/jpeg

pre-pended to the file's data.  I've been copying the good data out of the file by fgets()ing the first two lines, then looping through the rest of the file with fread() and fwrite()ing the data into a new file.  The following example shows the two header lines being removed, and the file(1) command confirming their contents:

<title>Upload test</title>
        // What type is the uploaded file?
        echo `file $uploadedfile`."<br>\n";

        // Open the file for the copy

        // Pull out the Content-Type header, and the empty 
        // line
        echo "header: $header<br>\n";
        echo "empty line: $header<br>\n";

        // Loop through the remaining file
        while(!feof($infile)) {

        // Test the type of the new file
        echo `file $`."<br>\n";

        // Test done - delete the file we made

This gives me output like the following:

/tmp/phpU7s9yh: image/gif 
header: Content-Type: image/gif 
empty line: 
/tmp/ GIF image data, version 89a, 100 x 30, 


/tmp/phpaWEhbG: application/octet-stream 
header: Content-Type: application/octet-stream 
empty line: 
/tmp/ MS-DOS executable (EXE), OS/2 or MS Windows 

I'm getting this problem using the PHP package compiled by RedHat (php-4.0.4pl1-3.i386.rpm and associated packages).

The configure command reported by phpinfo() is:

'./configure' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--enable-shared' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--with-exec-dir=/usr/bin' '--with-regex=system' '--with-gettext' '--with-gd' '--with-jpeg-dir=/usr' '--with-png' '--with-zlib' '--with-db2' '--with-db3' '--with-gdbm' '--enable-debugger' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-yp' '--enable-ftp' '--enable-wddx' '--without-mysql' '--without-oracle' '--without-oci8' '--with-xml'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-16 10:45 UTC]
Please try the latest CVS snapshot from
as I can not reproduce this.


 [2001-02-16 11:03 UTC] martinw at bluecho dot com
That fixed it - and I'm OK with this workaround for now until the next release is finalized.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 09:01:33 2024 UTC