What are the file types can we uploaded

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
umapathy
Forum Newbie
Posts: 14
Joined: Fri Jul 28, 2006 2:21 am
Location: chennai - india

What are the file types can we uploaded

Post by umapathy »

patrikG | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Dear All,

What are the file type can we uploaded ?
i can upload only images.
if i put document instead of images.it is not working 
can any one give me the code.
my code is here

Code: Select all

$path = 'E:\umapathy\Upload';

  // specify the filetypes allowed
 	$allowed = array('image/gif','image/pjpeg','image/jpeg','image/png');
 //$allowed = *.*;
  // specify the max filesize in bytes
 $max_size = 500000;
  if(isset($HTTP_POST_FILES['userfile']))
 {
  	if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
  		{
   			if($HTTP_POST_FILES['userfile']['size'] < $max_size)
   				{
    				if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed))
    					{
     						if(!file_exists($path . $HTTP_POST_FILES['userfile']['name']))
     							{
      								if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name']))
      									{
       										$html_output = 'Upload sucessful!<br>';
       										$html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'<br>';
       										$html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytes<br>';
       										$html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'<br>';
       										$image = $HTTP_POST_FILES['userfile']['name'] ;
      									}
      									else
      										{
       											$html_output = 'Upload failed!<br>';
       										if(!is_writeable($path))
       											{
        											$html_output = 'The Directory "'.$path.'" must be writeable!<br>';
       											}
       										else{
        										$html_output = 'an unknown error ocurred.<br>';      
       											}
      						   				}
     						 }
     						 else
     						 {
      							$html_output = 'The file already exists<br>';
     						 }
    				}
    				else
    				{
     					$html_output = 'Wrong file type<br>';
    				}
   				}
   				else
   				{
    				$html_output = 'The file is too big<br>';
   				}
    }
 }
 else
 {
  $html_output = '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
  $html_output .= '<input type="file" name="userfile">';
  $html_output .= '<input type="submit" value="upload">';
  $html_output .= '</form>';
 }
  
 echo '<html><head><title>Uploader</title></head><body bgcolor="lightblue">';
 echo '<b>'.$html_output.'</b>';
 echo '</body></html>';
  
 ?>
Regards

Umapathy


patrikG | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You'd be better search for a newer and better script.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Anything in digital format can be uploaded

Details:

http://www.iana.org/assignments/media-types/

http://en.wikipedia.org/wiki/MIME
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

For the current code, comment if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed)) and all files-types would be allowed.
Post Reply