PHP File Upload Functionality

function imageupload($photopath,$vphoto,$vphoto_name,$prefix)
{
$msg=”;
if(is_file($vphoto) and !empty($vphoto_name))
{
// Remove Dots from File name
$tmp=explode(“.”,$vphoto_name);
for($i=0;$i {
$tmp1[]=$tmp[$i];
}
$file=implode(“_”,$tmp1);
$ext=$tmp[count($tmp)-1];

$vlfname = $file.”.”.$ext;
//————————–

if($ext ==”jpg” || $ext ==”jpeg” || $ext == “gif” || $ext == “png” || $ext ==”JPG” || $ext ==”JPEG” || $ext == “GIF” || $ext == “PNG”)
{
$vphotofile=$prefix.$file.”_”.date(“YmdHis”).”.”.$ext;
$ftppath1 = $photopath.$vphotofile;
if(!copy($vphoto, $ftppath1))
{
$vphotofile = ”;
// $msg=rawurlencode(“Image Not Uploaded Successfully !!”);
$msg = 0;
}
else
{
// $msg=rawurlencode(“Image Uploaded Successfully !!”);
$msg = 1;
}
}
else
{
$vphotofile = ”;
//$msg=”Image Type Is Not Valid !!!”;
$msg = 2;
}
}
$ret[0] = $vphotofile;
$ret[1] = $msg;

return $ret;
}

$returnsfile = imageupload(“Path For file Upload”,$_FILES[‘Fileame’][‘tmp_name’],$_FILES[‘Fileame’][‘name’],”Prefix”);

Posted in: PHP