Mime type of blank form submission

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
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Mime type of blank form submission

Post by croniccoder »

Does anyone know what the mime type would be of a form that was submitted with a blank field? I am allowing users to upload files to my server using <input type="file/>.

There are some other input fields which users also fill out. I want to allow them to submit even if the "upload" form is blank, but I am limiting uploads to word or text files.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not test it and find out?
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Post by croniccoder »

I did. I am using an echo to try and print the mime type:

Code: Select all

$fileatt_type = $_FILES['uploadedFile']['type'];
echo $fileatt_type;
But it is blank. I don't know if that means it's NULL or an empty string or what?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

var_dump() or var_export() may be of interest then.
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Post by croniccoder »

var_dump returns string(0)
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Post by croniccoder »

I want to allow a person to upload a file. The file must be either a word document, or a plain text file. But I also want to allow the form processing to proceed even if the upload form is blank.

Code: Select all

$fileatt_type = $_FILES['uploadedFile']['type'];
$fileatt_name = $_FILES['uploadedFile']['name'];

if (!$fileatt_type  == "application/msword" ||  !$fileatt_type == "text/plain" || $fileatt_name == " ")
									{
But I can't figure out what the correct parameter for $fileatt_name or $fileatt_type would be if the form was blank for the upload?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

string(0) is an empty string .. not a space. Your last assertion should be $fileatt_name == "".
Post Reply