Heys, Guys i need Help i want to stop file overwrite when some upload file its check if file already exit same name like sample.jpeg then it will sample1.jpg
---------- Post added 1st Aug 2012 at 09:56 AM ---------- Previous post was 31st Jul 2012 at 06:21 PM ----------
solved
PHP:
<?php
require 'db.inc.php';
if(isset($_POST['up']))
{
function getExtension($name){
$pos = strpos($name,".");
$len =strlen($name);
$str =substr($name,$pos+1,$len);
return $str;
}
for($i=1; $i<=2; $i++)
{
$ext = getExtension($_FILES['img'.$i]['name']);
$allowed_filetypes = array("jpg","jpeg","png","gif");
//if($ext !="jpg" and $ext !="gif" and $ext !="jpeg" and $ext !="png")
if(!in_array($ext,$allowed_filetypes))
//if($ext!= in_array($Allow))
{
echo "Invlaid File"."<br />";
}
else
{
echo "Valid File"."<br />";
$path = "images/".$_FILES['img'.$i]['name'];
$name = $_FILES['img'.$i]['name'];
copy($_FILES['img'.$i]['tmp_name'],$path);
echo $path."<br />";
mysql_query("insert into img_data (url)values('$name') ")or die($query_error);
}
}
}
?>
---------- Post added 1st Aug 2012 at 09:56 AM ---------- Previous post was 31st Jul 2012 at 06:21 PM ----------
solved