...

View Full Version : uploaded imags dont have extensions?



Chris-2k
07-25-2012, 12:46 AM
Anyone can say why my images upload with no extension:

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

$tFiles = $_FILES['image_upload']['tmp_name'];
print_r($_FILES);

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.';
}

if(!empty($errors))
{
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');
}
}
}
?>

Thanks

DrDOS
07-25-2012, 01: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum