View Full Version : uploaded imags dont have extensions?

07-25-2012, 01:46 AM
Anyone can say why my images upload with no extension:

include $_SERVER['DOCUMENT_ROOT'] .'/includes/init.php';

$tFiles = $_FILES['image_upload']['tmp_name'];

for($i = 0; $i < count($tFiles); ++$i)
performaLocalUpload($_FILES['image_upload']['tmp_name'][$i], $uploadDir, $allowed, $maxfileSize);

function performaLocalUpload($files, $uploadDir, $allowed, $maxfileSize)
$oName = $_FILES['image_upload']['name'][$i];
$mType = $_FILES['image_upload']['type'][$i];
$fSize = $_FILES['image_upload']['size'][$i];

$ext = substr($oName, strrpos($oName, '.')); // grab file extension.
$ext = strtolower($ext); // get the extension of the file in a lower case format.

$errors = array();

// Do checks of the files.
if(in_array($mType, $allowed))
$errors[] = 'File type is not allowed.';

if($fSize > $maxfileSize)
$errors[] = 'Max file size is 4mb.';

foreach($errors as $error)
echo $error .'<br>';
} else {

$new_name = gen_uniqueFilename().$ext; //we will give an unique name.
$uploadFilePath = $uploadDir .'/'. $new_name;

if (!move_uploaded_file($files, $uploadFilePath)) {
trigger_error('Failed to upload image');


07-25-2012, 02:32 AM
You have a statement for 'not move_uploaded_file' but you don't have one for 'move_uploaded_file' so I don't think the uploaded file is even being sent to the folder. If you're going to rename the file anyway it's much easier to get the extension from the ['type'] data by using basename, and it's already lower case. But you're getting there. Make use of the data in the print_r statement since php already knows it.