Page 1 of 1

code for upload file with .doc extension formate

Posted: Wed Nov 01, 2006 8:49 am
by qumar
hi,

i need the code for upload the file in davabase and server with word formate(.doc extension) only.when i download it, it should open in word formate(.doc extension) only.
Please help to me.
Thanks.

Posted: Wed Nov 01, 2006 9:04 am
by amir
This is a good tutorial to upload files
http://www.zend.com/zend/spotlight/uploading.php

The other step is you want to upload only .doc. You can implement a simple check for it.

Code: Select all

if($_FILES['file_to_upload']['name'] != "") {
			$file_name = $_FILES['file_to_upload']['name'];
			$ext = explode(".", $file_name);
			$file_ext = $ext[1];
			
			if($file_ext == "doc") {
				// your code here
			}	
			else
				$error_format = "invalid format";
		}

Posted: Wed Nov 01, 2006 10:42 am
by volka
Do not rely on the value of $_FILES[...]['name'] or $_FILES[...]['type']. These are values the client sends and are not checked server-side.
If available use mime_content_type or the fileinfo extension

Posted: Wed Nov 01, 2006 11:01 am
by amir
client sends and are not checked server-side
Please explain a bit because PHP is a server side language so what is meant by this?

Posted: Wed Nov 01, 2006 11:28 am
by John Cartwright
In the nutshell, volka is saying don't trust anything that comes from the user without validating it (see last volka's last post on possible ways)

Posted: Wed Nov 01, 2006 2:48 pm
by amir
OK! Cheers.