Questions tagged [files]
Use it to generally reference to those files used on websites which could be video, images, pdfs, etc.
2,469
questions
153
votes
10
answers
213k
views
What are the recommended directory permissions?
I'm gearing up to deploy a Drupal 7 site and I can't find any documentation. What are the recommended security-conscious permissions for files and directories?
I am specifically interested to the ...
54
votes
19
answers
152k
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 ...
47
votes
4
answers
58k
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?
41
votes
1
answer
19k
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
7
answers
58k
views
Get the image URL
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 ...
24
votes
5
answers
19k
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
4
answers
28k
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?
21
votes
2
answers
34k
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 ...
21
votes
6
answers
16k
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
6
answers
16k
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
1
answer
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,...
20
votes
6
answers
25k
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', $...
20
votes
3
answers
38k
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?
20
votes
1
answer
13k
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 using the following code.
$uri = 'public://file.xyz';
// Take a look at: file.inc::file_load_multiple
$files = ...
19
votes
3
answers
15k
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
6
answers
16k
views
Change default favicon programmatically
I know I can load a favicon though the user interface, but is there a way of setting the default favicon for your theme, so that when someone enables the theme, the default icon is immediately used?
16
votes
3
answers
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 ...
16
votes
1
answer
6k
views
What are the most appropriate system permissions for 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 (...
15
votes
5
answers
37k
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.
15
votes
3
answers
14k
views
How do I save uploaded file permanently in file_manged table?
How do I save a uploaded file with status equal to 1 in the file_managed table, in Drupal 8?
Whenever I upload a file, it is stored in the file_managed table with status value 0.
I have used File::...
14
votes
5
answers
27k
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 ...
14
votes
2
answers
22k
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(...
14
votes
6
answers
6k
views
How to make existing public files private?
Let's say I have a node type "Article" which has a field "File" which is set to handle public files. A lot of articles and files get added.
Now the specs suddenly change and the "Article" will move ...
13
votes
2
answers
27k
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.
13
votes
4
answers
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
4
answers
11k
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 . # ...
13
votes
4
answers
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 ...
13
votes
1
answer
8k
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,...
12
votes
3
answers
13k
views
How to do file downloading in a controller function?
I asked the question about downloading of files upon submitting a form.
Now I want to clarify how to do it in the case of controller function.
That is, some controller is called and its function is ...
12
votes
5
answers
14k
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
6
answers
10k
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, ...
10
votes
4
answers
39k
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 ...
10
votes
8
answers
37k
views
The directory sites/default/files exists but is not writable and could not be made writable
We've recently had a few problems with our server, which seem to have been all patched up by myself, my host, and the cPanel team. However, since then we have been having problems with sites/default/...
10
votes
3
answers
21k
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 ...
10
votes
5
answers
19k
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
2
answers
6k
views
Site seems to miss the "private" wrapper, how can I fix it?
I can not enable the private folder getting the warning as below:
Warning: file_exists(): Unable to find the wrapper "private" -
did you forget to enable it when you configured PHP? in ...
9
votes
3
answers
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
3
answers
21k
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
4
answers
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?
9
votes
2
answers
7k
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 ...
9
votes
1
answer
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 ...
8
votes
3
answers
16k
views
How do I create a file download URL?
The function file_entity_download_uri() seems to no longer exist in Drupal 8.4, and I need to build a download URL for a file. I would not like to directly expose the file location.
8
votes
1
answer
6k
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
6
answers
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
4
answers
11k
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 ...
8
votes
2
answers
6k
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
1
answer
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
1
answer
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 ...
8
votes
4
answers
9k
views
Why does the favicon sometimes not show up and generate "page not found" errors, and other times does show up
As the question implies, on occasion Drupal's log is showing that the favicon is not found. Indeed, it does not show in the browser tab or address bar. At other times, even within the same surfing ...
8
votes
3
answers
887
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 ...