Forum Moderators: coopster
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
then following code:
$tmpName = $_FILES['userfile1']['tmp_name'];
IF(file_exists($tmpName))
{
IF(is_uploaded_file($_FILES['userfile1']['tmp_name']))
{
$fileName1 = basename($_FILES['userfile1']['name']);
$ext = getExtension($fileName1);
if ((in_array($ext, $valid_extensions)) && ($_FILES["userfile1"]["size"] < 2000000))
$tmpName = $_FILES['userfile1']['tmp_name'];
$fileSize1 = $_FILES['userfile1']['size'];
$fileType = $_FILES['userfile1']['type'];
after this i will sanitize the data using
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = rtrim($data);
$data = ltrim($data);
$data = htmlspecialchars($data);
$data = mysql_real_escape_string($data);
then i will change name of original file and attach the extension $ext that i stripped above and save this file under new name at a location in a folder in public_html
Interesting part is,when I tried to open the file,it will open as a JPG file and a picture will display but when i look through folder,it will show as php extension file.
if you recreate the image it should remove the issue
you need to do some better checks, maybe this will help
[webmasterworld.com...]