getting the file names from uploaded files

Home Forums Quform PHP getting the file names from uploaded files

This topic is: not resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6056
    ljackson
    Participant

    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 element

    and 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
    Luke

    #6065
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #6066
    ljackson
    Participant

    hi 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));
    }

    #6083
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy