Warminster - 2016-03-03

Hi Everyone, I am baffled as to why I can upload a png, jpg, gif, with no problem, but when it comes to uploading jpeg , it strips away the period just before the mime file ext ie " file_4_06281003032016jpeg " . my code line is below and if I adjust the -4 to minus 5 it overcomes the problem and places the period where it should be, BUT if I then upload an image with a 3 letter ext ie gif or jpg , it then adds the last letter onto the filename ie " file_4_06281003032016g.jpg ". Any pointers would ease my aching head !

if($FILES['field_4']['name']!='')
{
$field_4_filename = "file_4
".date("sihdmY").substr($_FILES['field_4']['name'],strlen($_FILES['field_4']['name'])-4);
if(!move_uploaded_file($_FILES['field_4']['tmp_name'], "../../files/".$field_4_filename))
{
die("

Sorry your image " . $_FILES['field_4']['name'] . " was not uploaded !

The max upload size is 500 kilobytes

Please ' RESIZE ' your image to less than 500kb before uploading.

Click the back button on your browser to return to the Editor.

");
}
}
///////////////////INSERT-QUERY//////////////////////////////
$query = "INSERT INTO events (field_1, field_2, field_3, field_4) VALUES('".mysql_real_escape_string($_POST['field_1'])."','".mysql_real_escape_string($_POST['field_2'])."','".mysql_real_escape_string($_POST['field_3'])."','" . "../../files/".$field_4_filename . "')";
}

 

Last edit: Warminster 2016-03-03