type = "text/plain"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaschulz
Forum Newbie
Posts: 8
Joined: Sun Feb 08, 2009 4:46 am

type = "text/plain"

Post by jaschulz »

When I upload a text file with IE8, the file fails this test:

if ($_FILES["uploadFile"]["type"] == "text/plain") {

but when I upload the same file with Chrome, Firefox, Opera or Safari, it passes the test.

What's going on here?

Thanks,

JAS
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: type = "text/plain"

Post by AbraCadaver »

$_FILES["uploadFile"]["type"] is not reliable because it is set by the browser and they may not do it the same way. IE8 probably sets it to application/octet-stream or something. You can use finfo_file() or mime_content_type().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jaschulz
Forum Newbie
Posts: 8
Joined: Sun Feb 08, 2009 4:46 am

Re: type = "text/plain"

Post by jaschulz »

I am very new at this. Can you show me the proper syntax for those alternatives (based on the model of what I was using)?

Thanks,

JAS
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: type = "text/plain"

Post by AbraCadaver »

Look at the manual for more examples:

Code: Select all

$type = mime_content_type($_FILES['uploadFile']['tmp_name']);
//or
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $_FILES['uploadFile']['tmp_name']);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jaschulz
Forum Newbie
Posts: 8
Joined: Sun Feb 08, 2009 4:46 am

Re: type = "text/plain"

Post by jaschulz »

OK. I used the mime_content_type alternative (finfo apparently requires php 5.3.0)

All is well on Chrome, Fifefox, Opera and Safari, but IE8 complains:

Warning: mime_content_type() [function.mime-content-type]: can only process string or stream arguments

That doesn't make any sense to me at all.

Any ideas?

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: type = "text/plain"

Post by John Cartwright »

You shouldn't be using mime_content_type() as it is deprecated. Try the fileinfo alternative (as suggested).
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: type = "text/plain"

Post by AbraCadaver »

jaschulz wrote:OK. I used the mime_content_type alternative (finfo apparently requires php 5.3.0)

All is well on Chrome, Fifefox, Opera and Safari, but IE8 complains:

Warning: mime_content_type() [function.mime-content-type]: can only process string or stream arguments

That doesn't make any sense to me at all.

Any ideas?

Thanks.
This shouldn't have anything to do with the browser. Show the code.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jaschulz
Forum Newbie
Posts: 8
Joined: Sun Feb 08, 2009 4:46 am

Re: type = "text/plain"

Post by jaschulz »

Something is weirdly wrong. Here is my test code:

<?php

$mystring = "mystring = " . $_FILES["uploadFile"]["tmp_name"];
echo $mystring;

?>

It works fine in Chrome etc. But in IE 8 it returns only the constant text (i.e. "my string =") and nothing at all for $_FILES["uploadFile"]["tmp_name"].

My host (bluehost.com) is running php 5.2.1.

Can anyone tell me what's going on here?
jaschulz
Forum Newbie
Posts: 8
Joined: Sun Feb 08, 2009 4:46 am

Re: type = "text/plain"

Post by jaschulz »

It turns out the problem is in my javascript. I am doing (or trying to do) something fancy to deal with the mess that the different browsers make of the HTML file input, and somehow that is preventing IE from actually sending the name of the file I am trying to upload. I'll try to figure this out tomorrow, and explain it in a new thread.

Thanks.
Post Reply