Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Validating Image files using php

Links for php scripts

Moderators: macek, egami, gesf

Validating Image files using php

Postby amruth » Fri Jan 06, 2012 9:56 am

I am posting the file from client side HTML <input type=file...> and I wrote a PHP script at server side to check whether the uploaded file is image or not as if($_FILES["file"]["type"]=="image/jpg"....).
But this code does not check the actual content of the file uploaded,i.e if someone renames other file types as .jpg or .png etc then my script takes it as image file.

Anybody please help me.

New php-forum User
New php-forum User
Posts: 2
Joined: Fri Jan 06, 2012 9:23 am

Re: Validating Image files using php

Postby soumitra » Mon Jan 09, 2012 4:42 am

File Upload in PHP

----------------Save it any name--------------------
<title>img upload</title>
<form name="frm" method="post" action="upload2.php" enctype="multipart/form-data">
<td>Select File </td>
<td><input type="file" name="img" value="" /></td>
<td><input type="submit" name="sub" value="UPLOAD" /></td>

ANOTHER PAGE NAME---upload2.php.

if ($extension == "jpg" || $extension == "flv" )
//size cheack max size=2m.b (2097152 byte)
if ($size<="2097152")
if ($p)
echo "UPLOAD secessful";
else echo "NOT UPLOAD";
echo "invalid size";
echo"INVALID file format";
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jan 05, 2012 9:23 am

Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.