<?php
error_reporting(0);
$fileName=$_FILES['fileImage']['name'];
$file=$_FILES['fileImage']['tmp_name'];
$path='image/'.$_FILES['fileImage']['name'];
$extension=fileGetEXT($fileName);
function fileGetEXT($fName)
{
$fileName=$fName;
$start=strpos($fileName,".");
$getEXT=substr($fileName,$start+1,4);
return($getEXT);
}
function createUniqueFile($fName)
{
$fileName=$fName;
$start=strpos($fileName,".");
$name=substr($fileName,0,$start);
$getEXT=fileGetEXT($fileName);
$counter = 1;
while(file_exists($newFileName=strip_tags('image/'.$name.'~'.$counter.'.'.$getEXT)))
{
$counter++;
}
return $newFileName;
}
$validEXT=array("jpg","jpeg","gif","bmp","png");
if(isset($_POST['submit']) && ($_POST['submit']=="Submit"))
{
if(in_array($extension,$validEXT))
{
if(file_exists($path))
{
$newFile=createUniqueFile($fileName);
$path1=strip_tags($newFile);
move_uploaded_file($file,$path1);
echo ucfirst($extension)." Valid Extension";
}
else
{
move_uploaded_file($file,$path);
echo ucfirst($extension)." Valid Extension";
}
}
else
{
echo ucfirst($extension)." Invalid Extension";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Uploading</title>
</head>
<body>
<form name="uploadFrm" method="post" action="" target="" id="" enctype="multipart/form-data">
<table align="center" style="border:#666666 solid 1px; margin-top:20px;">
<tr>
<td>First Name:</td>
<td><input type="text" name="txtfirstName" value="" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="txtLastNAme" value="" /></td>
</tr>
<tr>
<td>Image:</td>
<td><input type="file" name="fileImage" value="" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
Blogger templates
Blogger news
Blogroll
Archives
-
▼
2013
(219)
-
▼
February
(22)
- For removing content of a directory - subdirectory...
- print_r() in php
- File Upload if File Exists Append Number to File N...
- PHP Operator Types
- VBA writing in a text file
- PHP installation
- delete cookies in php
- Installing CPAN modules in perl in linux.
- PHP File Inclusion
- Subhajit Das | PHP Developer | PHP Programmer
- Assignment #2 Modified.
- Writing oracle procedure.
- Simple Ajax Example
- insert data into table in php with mysql
- rand() in php
- Send Email Using SafSendMailV2
- Free php pdf tutorial
- Get in between text using SafGetInBetweenText
- ckeck ip address is in blocked list or not in php
- codeigniter routing issue fixation - url rewriting...
- Best Free PHP IDE
- Array to Single Variable
-
▼
February
(22)