From:             [EMAIL PROTECTED]
Operating system: RedHat Linux 7.0
PHP version:      4.0.4pl1
PHP Bug Type:     HTTP related
Bug description:  HTTP File upload, Content-Type header is stored at the beginning of 
the file

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'

Edit Bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to