Questions tagged [files]

Use it to generally reference to those files used on websites which could be video, images, pdfs, etc.

Filter by
Sorted by
Tagged with
142
votes
11answers
184k views

What are the recommended directory permissions?

I'm gearing up to deploy a Drupal 7 site and I can't find any documentation about what the recommended security-conscious file and directory permissions should be set to. Specifically default/files/ (...
48
votes
17answers
126k views

Configuring the temporary directory

I have recently moved a site from a localhost to a VPS. I have managed to make the public and private files writable; however, I am not sure where to find the temporary folder and how to change the ...
43
votes
4answers
47k views

How do I get the path for public://

I need to get the path for public:// at runtime. Is there a function I can use to get it?
39
votes
1answer
18k views

Managed file: the file used in the field may not be referenced

I am having some issues with the managed_file type. Whenever I try to edit and save a form that has a managed_file element in it an error occurs: The file used in the Picture field may not be ...
24
votes
5answers
17k views

How to set value of file field with entity_metadata_wrapper

How do you set the value of a file field when using the entity_metadata_wrapper? I've tried doing this in code: $file = new stdClass(); $file->uid = 1; $file->uri = $file_path; $file->...
22
votes
5answers
35k views

Get Image URL in Twig

I want to render an image as a background image via an inline style in twig. I created a field called bg_image and attached it to the standard plain page. After fiddling around for hours I was able ...
22
votes
6answers
15k views

How to upload multiple files at once?

We need to upload multiple files of different types, is there a module that will check for valid mime types and upload only the valid files, (based on site settings, eg: png, doc, jpg, txt) ?
21
votes
3answers
34k views

How to get drupal 7 default file upload directory?

I have trouble to get the upload directroy from drupal. Is there some function returning the relative or absolute path?
21
votes
6answers
13k views

How to find orphaned files and images which are not linked from any css stylesheet or from any node?

Is there a way to list all unused files which reside inside public file system and inside a theme directory and list them, or maybe even have an option to delete them automatically? I mean files ...
21
votes
1answer
1k views

Mass image upload with Storage API and Services API

I am trying to set up a site that will be storing a large amount of images (roughly 50,000 to start with). The strategy for this was to use Storage API and S3 storage to deal with the costs of hosting,...
18
votes
3answers
20k views

How to check if (unmanaged) file exists?

I can't find a Drupal API function in D7 that tells me if an (unmanaged) file exists. D6 had a file_check_location but not for 7. How to check if (unmanaged) file exists?
17
votes
3answers
12k views

How do I change the temporary directory without using any administrative pages provided by Drupal?

I've moved my live Drupal website to Windows localhost (XAMPP), but I'm getting lots of "The file could not be created" errors. If I log in to the site as an administrator, it fails to return any more ...
17
votes
3answers
8k views

Is there anywhere a good writeup on Drupal directory structure?

I wonder if there is a good writeup on Drupal directory structure?
16
votes
3answers
14k views

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

I'm looking to do something like this $fid = 15; $file = (array)file_load($fid); $content = drupal_render($file); echo $content; file_load() drupal_render() And specifically this fid is from the ...
14
votes
4answers
3k views

Can Drupal be configured to find modules in other locations?

I put my modules in sites/all/modules. Is there a way to configure Drupal to find more modules in other locations as well? Edited I use Virtual Hosts often but not in the way you described. The ...
13
votes
4answers
25k views

how to get the absolute path for files based on fid

How can i get the absolute path for a file based on the fid? Sorry if this is a repeat, I did a search but was unable to find the answer.
13
votes
1answer
5k views

What are the most appropriate users and permission levels for Drupal sites on shared hosting?

Although the Drupal site goes into great detail about permissions and security, there are only vague/unclear references to shared hosting. From a Drupal point of view, what is the most secure set-up (...
12
votes
4answers
16k views

Storing data / session for anonymous user

I am working on a shop, and for the cart, i need to store items before payment. $tempstore = \Drupal::service('user.private_tempstore')->get('boutique'); $tempstore->set('poids', $...
12
votes
2answers
25k views

Where are temporary files created?

I want to know where Drupal (or its modules) create temporary files. Are they put in sites/default? I'm especially talking about Drupal 6.
12
votes
4answers
8k views

Why can't I add another allowed file extension to a Drupal 7 image field?

I've added the SVG file extension for image uploads via admin/structure/types/manage/image/fields/gallery_image, as you see below: But when I go to upload an image, I'm still not allowed to ...
11
votes
5answers
12k views

How to change File field icons (without changing core)?

The generated markup for displaying a file field is (PDF in this example): <img src="/modules/file/icons/application-pdf.png" title="application/pdf" alt="" class="file-icon"> I'd like to use ...
11
votes
1answer
496 views

Drupal file_copy is not working

I have the following code: $main_image = glob('main*.{jpeg,gif,png,jpg,JPEG,JPG,PNG}', GLOB_BRACE); if (count($main_image) != 1) die("Could not find main picture !"); $file_path = ...
10
votes
2answers
10k views

Get the real path of a file

I am creating an Excel reading module in Drupal 8. I want to get the real path of a file for reading it from a path like public://2016-03/Places.xls. What function should I call for getting the real ...
10
votes
3answers
8k views

Drush and user permissions

I see that my user is a member of the apache group. I added and confirmed via the following $ sudo usermod -a -G apache `whoami` # add my user to apache group $ sudo chmod -R g+w . # ...
10
votes
4answers
13k views

How do I add embedded YouTube videos in a field?

I would like to have a field for adding YouTube videos; however, I do not want to use the Media module because it is very buggy at this point. Is there any alternative for Drupal 7?
10
votes
2answers
8k views

How to get the url of a file field of a given node?

$node->field_file gives me a FileFieldItemList while the first entry seems to be a FileItem. $node->field_file->getValue() gives me an integer (I guess the file id). How can I actually get ...
9
votes
6answers
8k views

Files attached to nodes are never deleted from server even after they're removed from the node (and that edit is saved), Drupal 7

I've noticed something strange on my site: after attaching a file to a node (via the regular file field), that file never gets deleted from the server. I remove it from the node, save that change, ...
9
votes
5answers
17k views

Preview image after uploading using Form API

I uploaded an image file using the managed_file Form API type, but after uploading the image it does not appear as a thumbnail beside the field. What is rendered is the file name of the image with a ...
9
votes
3answers
4k views

How to configure D7 so files get uploaded to a different server

In Drupal 7, the default path for uploading is set in the File system options in the Public file system path. Is it possible to specify a different server in this path? I have a Drupal 7 web site we ...
9
votes
3answers
5k views

How do I redirect users to a predetermined url after login?

I have a view in Drupal 7 that lists PDF files. I want to keep track of the users that open that file; so I want that, if they are not logged in when they click, they are sent to the login/sign up ...
9
votes
3answers
20k views

Form Api File upload

I have the following code in my form. $form['new']['upload'] = array( '#type' => 'file', '#title' => t(''), '#size' => 40, ); On the submission handler, it returns the file name but ...
9
votes
4answers
10k views

How to save images using Services 3

I have found some very detailed tutorials about Services 3. I appreciate them very much here is a small list. http://drupal.org/node/1354202 How to add multiple images to a node using node.save ...
9
votes
1answer
4k views

Will managed files be deleted if no corresponding entry exists in file_usage?

I am using the services module to implement a REST API. One resource allows POSTs with uploaded files. During a services pre-process function I save the file to the temp directory. During a ...
9
votes
3answers
793 views

How can I take control of the rendering of a file entity when inlined in text?

There are excellent instructions for how to allow embedding Media into text fields here Setting up WYSIWYG and CKEditor to include Media Browser / Embed Media button. Now I'm trying to control the ...
8
votes
3answers
19k views

Image Upload in a Custom Module

I'm writing a custom module, and I need it to upload an image. I'm having trouble finding good documentation on this, but I think I'm close. What am I missing? $file returns false in the form ...
8
votes
1answer
10k views

Get the public path directory

I want to save file programmatically in public path, and I want to know how can I get Public Directory path in Drupal 8. In Drupal 7, I would use the following code. drupal_realpath(...
8
votes
5answers
900 views

Where can I download old releases of Drupal?

I'm trying to find a copy of 6.20 to run a diff on a client's Drupal install. I believe there's been changes to core. How can I get version 6.20? Additionally, how can I download any older Drupal ...
8
votes
1answer
5k views

How do I add the file size to a view?

After reading and searching through related topics, I have not seen any clear answer about how to show the file size in a Views created file list. Im using Drupal 7 and having File 7.14 field ...
8
votes
6answers
10k views

Attaching existing server files to filefield

How do you set an existing file path for a file field, in Drupal 7? The only option I see is to upload the file again. In Drupal 6, FileField Sources seems to do this. Does FileField Paths or IMCE ...
8
votes
2answers
5k views

Warning: file_put_contents(temporary://): failed to open stream [duplicate]

I get this message from Drupal: Warning: file_put_contents(temporary://file8vyLsO): failed to open stream: "DrupalTemporaryStreamWrapper::stream_open" call failed in file_unmanaged_save_data() (...
8
votes
2answers
5k views

Example of hook_file_download

How do I restrict the access to certain files based on their content type? I have the download section for registered users, and I want to prevent them to post links somewhere outside my site. Is ...
8
votes
1answer
4k views

Upload progress on nginx

I am using the latest version of Drupal 7 and my webserver is Nginx. I checked the status report and it says: Upload progress Not enabled Your server is not capable of displaying file upload ...
8
votes
1answer
2k views

Prevent file renaming

I have a user who is uploading a number of files with the same file name. It is important to them that the files are never renamed. However, the files are getting _1, _2, etc on the end. Is there a ...
7
votes
3answers
30k views

How do I get the public url of a file from the uri or filename

I'm using php from with a view (Views PHP) I'm trying to extract the real url of a file from a file reference. I am able to get the the uri of the file and or the filename. What drupal function can I ...
7
votes
1answer
5k views

How does the tmp folder work? It stores lots of junk files and takes space

My tmp folder is set to /sites/default/files/tmp/ and I checked what's inside and for example there is folder inside called /update-cache-b2903cc4/ it keeps all modules in .zip that I installed via '...
7
votes
1answer
3k views

Load a file entity by URI

Is there a way to load a file by URI in Drupal 8? In Drupal 7 it is possible by the next example: $uri = 'public://file.xyz'; // Take a look at: file.inc::file_load_multiple $files = ...
7
votes
3answers
11k views

Embed media in Ckeditor field for drupal 7

I'm looking for a plugin for the latest version of CKeditor (3.6.3) so that I can add youtube videos (and other embedded media) to a text area that uses ckeditor. I found several proposed plugins ...
7
votes
2answers
6k views

File issues after importing Drupal site

I recently tried to move my Drupal site to a new server using this page: Moving Drupal 7 site to a new server. But now the style doesn't seem be loaded and more importantly I get this error on every ...
7
votes
2answers
3k views

Public and temporary files error in my “Status Report”

I just upgraded to 7.25 from 7.19, and now in my Status Report I have a red X on my "Public Files" and "Temporary Files". See http://drupal.org/SA-CORE-2013-003 for information about the ...
7
votes
1answer
3k views

Delete “permanent” file when it has 0 uses

Files that are "used in 0 places" (viewable at /admin/content/files) are not being deleted automatically by cron. They also show a status of permanent. How do I allow these files to be deleted by cron,...