Questions tagged [files]
Use it to generally reference to those files used on websites which could be video, images, pdfs, etc.
214
questions
153
votes
10
answers
212k
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 ...
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 ...
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 ...
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 (...
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->...
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 ...
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 ...
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', $...
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 ...
1
vote
2
answers
1k
views
How to concatenate all token values of a list in a single field within a Rules loop?
I am attempting to send a list of uploaded files on a newly created node via email.
In a content type, I have a File Field that allows unlimited values.
Within Rules, I created a loop calling the ...
7
votes
3
answers
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 ...
4
votes
3
answers
10k
views
How do I change the uploaded file name after the node has been saved?
How can I change the name of an uploaded file after the node has been saved?
I know there is the FileField Paths module for this purpose, but it's still buggy for Drupal 7. I looked at the source of ...
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?
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.
7
votes
2
answers
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
...
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 ...
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
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(...
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 ...
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
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 ...
5
votes
2
answers
6k
views
Changing the link title in a view for generic file
I have a bunch of files that are displayed in a view; i'm using 'generic files' setting to display them; the problem is that some files have really ugly names like '1002-32-eda.pdf' i'd like to change ...
5
votes
4
answers
15k
views
Installing modules without FTP
So I have installed the latest Drupal 7 stable on my new server, and it asks for an FTP user/password every time I try to install a new module from a .zip file. (Or using an URL).
The problem is ...
4
votes
3
answers
4k
views
Move file storage to another server
Consider this:
I have one fast server with a Drupal installation but this server does not have access to a lot of disk space.
I have another server that isn't quite as fast but does have access to ...
4
votes
3
answers
15k
views
Why drupal_realpath('public://') returns an incorrect path?
I am calling drupal_realpath('public://') inside a module function.
Why am I getting a path like sites/all/modules/current_module/sites/default/files from drupal_realpath('public://')?
4
votes
2
answers
2k
views
How to keep underlying file when deleting a Filefield value
I have a Content Type with a FileField (Image, in particular). When one of these values is deleted, then Drupal deletes the underlying file as well (as long as no other nodes reference the same file).
...
3
votes
1
answer
4k
views
How to download file upon submitting a form?
I have a form with the submit button.
And I have a file in '/sites/default/files/tmp/my_doc.docx'
I'm trying to download the file upon submitting the form.
Here is my code
public function submitForm(...
3
votes
2
answers
3k
views
Changing file name on upload
I'm trying to automatically add prefixes to uploaded file names so they can later be processed by non-drupal scripts. I want to do that while the user is uploading files during creation/editing of a ...
3
votes
4
answers
6k
views
How to link the file icon to the file and to hide the filename?
I have uploaded files to be displayed in a table together with some other informations (title, tags etc). One row of this table the filename which links to the downloadable file. Next to the filename ...
2
votes
3
answers
4k
views
Uploaded images in theme settings is going to be lost
I have a flexslider and I make its images customizable through the theme settings. I added a caption property for the the slide to meet multiple languages websites as follows in theme-settings.php:
//...
1
vote
2
answers
4k
views
How to set MINIMUM number of required fields?
I need to set the minimum number of required values for several file fields in Drupal 7. I can only find options to make the field required or set a maximum number of allowed values. Is there any way ...
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?
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?
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 ...
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
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/...
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 ...
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 ...
7
votes
1
answer
7k
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
2
answers
7k
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 ...
6
votes
3
answers
8k
views
Get raw and relative path of a file uri
I have a file with an uri and I want to get its raw and relative path.
Uri: public://videos/Test Video.mp4
Path: /sites/default/files/videos/Test Video.mp4
I found already a way to do this:
$...
6
votes
2
answers
890
views
Drupal files folder owner/group for CentOS?
This is my first time installing Drupal on CentOS. I know for Ubuntu it needs to be www-data as the /files folder owner, but what is it for CentOS?
6
votes
2
answers
19k
views
How do I delete files the correct way?
I have added a file attachment field to my basic pages.
Now for instance I want to delete a certain file from a page, how should I approach this?
I know deleting it from the file system isn't the ...
5
votes
1
answer
3k
views
Problem with dependency injection (File::load and \Drupal::service)
In order to make a managed_file field permanent I did this in my module configuration form:
<?php
namespace Drupal\my_module\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\...
5
votes
1
answer
1k
views
Bulk saving nodes with a file field
I'm in the progress of creating a bulk upload function for a Drupal site. Using flash I'm able to upload the files to a specific url that should be able to handle the files.
What I want to do, is not ...
5
votes
5
answers
4k
views
Drag & drop files into drupal site?
Does anyone know of a module that allows to drag files from users computer into a target area in site (like in gmail or wordpress)?
ideally this would work with Image and other modules to insert the ...
3
votes
2
answers
3k
views
Why drush fails to rsync between my two local instances?
I'm trying to synchronize two local drupal repositories using the following command:
drush rsync
My environment:
- drush 6.1
- Mac os X 10.9
- drupal 7.24
I have followed standard security ...
3
votes
4
answers
5k
views
How do I save a file with managed_file in a theme?
I'm developing a theme that it requires to have a header image on the front page, so I have this.
casper.theme
function casper_form_system_theme_settings_alter(&$form, &$form_state) {
$form[...
3
votes
2
answers
1k
views
How to restrict access to private files to members of an organic group?
I have an organic group with a file field that stores its files in a private directory (sites/default/files/private/).
These files are visible only to members of that group. But, as is commonly known, ...
2
votes
2
answers
3k
views
Drupal 8 Theme Header Background Image Upload
I'm upgrading the Mayo theme to Drupal 8. For Drupal 7 it worked like this in theme-settings.php with hook_form_system_theme_settings_alter():
$form['adv_header']['header_bg'] = array(
'#type' =...