code for upload file with .doc extension formate

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
qumar
Forum Commoner
Posts: 29
Joined: Wed Nov 01, 2006 8:20 am

code for upload file with .doc extension formate

Post 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.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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";
		}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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)
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

OK! Cheers.
Post Reply