1

I have a webform that allows users to upload their CV/Resume's. The webform is sending me the file ID. I know that the URL for accessing those files is https:// example.com/sites/default/files/webform/myfilename.

Can I access the file using the file ID instead of its name, for example https:// example.com/sites/default/files/webform?fileid=1502?

3 Answers 3

1

If you're looking to do this in code, I believe that this question has already been answered:

Given a File ID (fid) how can I get the HTML that represents that fid?

You can also access the file's page at yoursiteurl/file/fid, but this isn't a direct link to the file.

0

Yes. You can use the drupal file_load() function to load the uploaded file.

<?php

$fid= 1502;
$file = file_load($fid);

?>

It will return the details of a file in the form of an array.

Hope it works for you!

0

file_load() has been deprecated

Instead, in a custom module you can use the function Drupal\file\Entity\file::load($fid) to load a file with the file ID that is present in the webform submission values

Here is an example :

  use Drupal\file\Entity;

  function student_support_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state){

     $values = $form_state->getValues();

       if(!empty($values['file'])){
         $file = Entity\File::load($values['file']);
         $values['file'] = $file->getFileUri();
       }
     ...
    }

Here 'file' is the key of your webform fileUpload element and $values['file'] would be an integer.

2
  • Welcome to Drupal Answers! :-) That's very interesting indeed. Unfortunately I doubt this answers OP's question...
    – leymannx
    Dec 23, 2019 at 19:23
  • 1
    This seems a comment for a previous answer. As for answering the question, I think none of the answers really answered it, since the OP seems to ask about a link to access the uploaded file given its ID.
    – apaderno
    Dec 24, 2019 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.