How can I programmatically store an image in a publicly accessible location on my Drupal site?
I am writing a Drupal module where users send down content (formatted as HTML). The content will almost always include <img>
tags. Those tags will reference the user's server. But, I don't want to hit the user's server every time that content is requested; I want to serve up a version on my server.
So, I have written a function to look through the HTML for <img>
tags and then use cURL to save them locally. All is well - except I can't figure out where in my local filesystem to store the images, thanks to Drupal's crazy URL-rewriting. Ide开发者_如何学JAVAally I could put them in a directory that is already accessible over the web and not have to create any new directories.
Any thoughts?
TIA,
BenjyP.S.: Not really feasible to use an ImageField
as I need to display the image inline. Thanks!
In theory, you should be able to put them anywhere under the webroot, and they'll be servable, but normally, content images (as opposed to theme images) go in your files
directory, which is usually configured as /sites/default/files
. I usually, put a sub-folder to add some structure, so I'd put them in /sites/default/files/images/scraped
(or whatever).
Note: you can get the file path with file_directory_path. You might also look at the file handling api.
why you don't put it in drupal directory? by default, sites/default/files
精彩评论