Home › Forums › Quform PHP › getting the file names from uploaded files
- This topic has 3 replies, 2 voices, and was last updated 11 years, 3 months ago by Ally.
- AuthorPosts
- August 27, 2013 at 9:30 pm #6056ljacksonParticipant
Hi,
I am using the multi upload element and have managed to get the files to upload to the the upload folder but i also want to insert the filenames of the files in my database so i know who has uploaded them and what they are related to.
this is the element code
// Process uploaded files
foreach ($elements as $element)
{
if ($element instanceof Quform_Element_File
&& array_key_exists($element->getName(), $_FILES)
&& is_array($_FILES[$element->getName()]))
{
$file = $_FILES[$element->getName()];if (is_array($file['error']))
{
// Process multiple upload field
foreach ($file['error'] as $key => $error)
{
if ($error === UPLOAD_ERR_OK)
{
$fileData = array(
'path' => $file['tmp_name'][$key],
'filename' => Quform_Element_File::filterFilename($file['name'][$key]),
'type' => $file['type'][$key],
'size' => $file['size'][$key]
);if ($config['saveUploads'] && $element->getSave()) {
$result = Quform_Element_File::saveUpload($config['uploadPath'], $config['uploadUrl'], $fileData, $element);if (is_array($result)) {
$fileData = $result;
}
}if ($element->getAttach()) {
$attachments[] = $fileData;
}$element->addFile($fileData);
}
}
}
else {
// Process single upload field
if ($file['error'] === UPLOAD_ERR_OK) {
$fileData = array(
'path' => $file['tmp_name'],
'filename' => Quform_Element_File::filterFilename($file['name']),
'type' => $file['type'],
'size' => $file['size']
);if ($config['saveUploads'] && $element->getSave()) {
$result = Quform_Element_File::saveUpload($config['uploadPath'], $config['uploadUrl'], $fileData, $element);if (is_array($result)) {
$fileData = $result;
}
}if ($element->getAttach()) {
$attachments[] = $fileData;
}$element->addFile($fileData);
}
}
} // element exists in $_FILES
} // foreach elementand i have tried this
//INSERT INTO TBL UPLOADS
foreach($attachments as $image)
{
$query4 = "INSERT INTO tbl_uploads (fileLocation) VALUES ('$image')";
mysqli_query($con, $query4) or die(mysqli_error($con));
}but this returns array?
can anyone help me to get the filename and extension please (filename.jpg) of each of the files uploaded
thanks
LukeAugust 28, 2013 at 9:50 am #6065AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 28, 2013 at 1:45 pm #6066ljacksonParticipanthi mate,
got it working 🙂 thanks
here is the updated code
foreach($attachments as $image)
{
$filename = $image['filename'];
$query4 = "INSERT INTO tbl_accommodation_images (accommodationID,fileName) VALUES ('$aID','$filename')";
mysqli_query($con, $query4) or die(mysqli_error($con));
}August 29, 2013 at 12:34 pm #6083AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.