Language: PHP / Using Class Upload by Colin Verot
About: Multiple Uploading
The code below already uploads the files fine, it works…
PROBLEM: I am having trouble figuring out how to get the filename extension.
(In a comment below, I have specified where my problem area is…)
// CONNECTION TO DATABASE HERE...
// INCLUDE UPLOAD CLASS LIBRARY
include (dirname(__FILE__).'/lib/class.upload.php');
$files = array();
foreach ($_FILES['fileupload'] as $k => $l)
{
foreach ($l as $i => $v)
{
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
$imagename = $_FILES['fileupload']['name'];
}
}
foreach ($files as $file) {
// THIS IS MY PROBLEM AREA, GETTING FILE EXTENSION
$ext=strchr($imagename,".");
$generate_name = rand(100,99999);
$generate_name_extra = rand(200,9999);
$filenamex = "PHOTO_".$generate_name.$generate_name_extra."_".time();
$filenamex_thumb = $filenamex."_thumb";
// COMPLETE FILENAME WITH EXTENSION
$filename = $filenamex.strtolower($ext);
$handle = new upload($file);
if ($handle->uploaded) {
///// 1 ////////////////////////////////////////////////////////////////////
$handle->file_new_name_body = $filenamex_thumb;
$handle->image_resize = true;
$handle->image_x = '300';
$handle->image_ratio_y = true;
$handle->jpeg_quality = '100';
// ABSOLUTE PATH BELOW
$handle->process($absoRoot.'covers/thumbs/');
if ($handle->processed) {
// SUCCESSFUL RESPONSE
}
else
{
// FAILED RESPONSE
}
}
}
And the webform is:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="fileupload[]" id="fileupload" type="file" multiple>
I really pretty much need the file extensions to serve the files correctly online, but I can’t spot where to find it. I have tried using: $files[$i][$k] instead of $imagename in my specified problem area above, as well as $file and other possible solutions, but I can’t spot which one’s going to give me the filename with extension.
Hopefully someone could point it out. Thank you for your time and assistance!
1 Answer