How to attach local files to Drupal nodes - drupal

I need to attach video files to nodes in Drupal 6, yet the AJAX uploader fails (the dreaded HTTP error 0), and anything I tried to debug it didn't help (may be moving to Drupal 7 will, but that's still going to be some time). Is it possible to somehow upload the file to the server via FTP, and then simply attach it to a node, so that it is linked in the same way that it would be linked after a regular file attachment?
This is not about CCK's FileField. This is about the "vanilla" node attachments. To do the same for FileField uploads I used FileField Sources module, and I'd like to find a similar solution for the node attachments.

your problem is in limit upload file size.
check it is in php.ini settings
do not forget that max package size limits upload size too
check drupal settings (drupal file system settings or filefield settings)

I believe I had something like this problem when I configured a site to run over SSL but not all the URLs in the system were being properly adjusted or redirected. I set the $base_url variable in settings.php to use https://www.example.com` and the error stopped.
In my case I believe it related to a Taxonomy tagging autocomplete callback, but all Ajax callbacks in the system can be sensitive on this point.
#646694 AJAX: Terrible reporting of status 0 response from AJAX request ("HTTP Error 0 has occurred")

Since I couldn't find a solution, I had to switch to using CCK FileField, and use FileField Sources module (http://drupal.org/project/filefield_sources) to upload files to the server and then attach them to the field.
Thanks for trying to help me, guys!

Related

Javascript & CSS not loading after Drupal 8 migration

I have been given the task of moving two Drupal-based websites to a new server, not because I'm a Drupal expert but I'm the only one in the office with PHP programming skills. One is a Drupal 7 site, the other Drupal 8. These were both given to me as DevDesktop archives and SQL dumps. The Drupal 7 site was pretty straightforward - copied the contents of the docroot up to the new server, created and populated a new MySQL database and edited the default site settings file to point at the new dbase. So the Drupal 7 site works fine. Doing the same with the Drupal 8 site the main problem seems to be it won't load any CSS or Javascript.
In the Javascript Console it threw me off the scent slightly because it said the mime type of the CSS was incorrect, but on further inspection that's because the path to the CSS was returning a 404.
Compounding the problem is Antibot, and as Javascript isn't loading, although I have the username and password for the admin user, I can't login because Antibot keeps sending me back to the homepage telling me to enable Javascript. I have edited settings.php to enable /core/rebuild.php and tried that, but doesn't appear to make any difference. I've also manually truncated the 'cache_...' tables and that doesn't seem to work either. Note that I DON'T have access to SSH on the new server, so can't use drush.
Refused to apply style from '[]' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Failed to load resource: the server responded with a status of 404 (Not Found)
What it does look like to my non-expert eye is that Drupal is configured somehow to server up optimised versions of the CSS and JS from virtual directories /css/ and /js/, although those paths don't actually exist on the server. I checked the .htaccess file, but other than some clever stuff to deliver gzipped versions to gzip-capable browsers, couldn't see anything in there that would get the server to the correct file. Perhaps if someone could explain how Drupal routes a request to /css/ or /js/ to the right file, that would help my understanding further.
Ultimately I think this problem is because Drupal 8 wants to deliver optimised files, but the cache is screwed and Antibot won't let me get into admin to turn off aggregation.
I have full access to the server files and database, but not drush. Is there a way to turn off the CSS & JS aggregation apart from via the admin menus?
In this situation you can disable aggregation either :
by editing settings.php or settings.local.php :
/**
* Disable CSS and JS aggregation.
*/
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
or via sql, but you have to decode and unserialize blob data from the config table to make the changes, and then make the reverse process :
# Query :
SELECT name, CONVERT (`data` USING utf8) FROM config WHERE `name`='system.performance';
# Unserialize query output and edit data locally
$config = unserialize($output);
$data['css']['preprocess'] = FALSE;
$data['js']['preprocess'] = FALSE;
# Then serialize data and write it back into the config table
# (original encoding is probably `LONGBLOB` but it may differ depending on the backend).
Once you can ssh into the server, you will need to reset permissions and ownership under sites/default/files/ before enabling aggregation again :
mkdir -p sites/default/files/{css,js}
chown -R apache:apache sites/default/files/
chmod -R 0755 sites/default/files/
You may also want to check if the public file path setting (in settings.php) is properly set according to where these ressources are actually located :
$settings['file_public_path'] = 'sites/default/files';

Wordpress File Upload Hook

I am trying to hook into the Wordpress file uploader and would like some suggestions. I would like to be able to grab the path of the source file (not WP path; i.e. K:\docs\file.pdf) so I can download another file of the same name (different extension) & path automatically (i.e. K:\docs\file.txt).
Wordpress provides hooks for after the file is uploaded but all path information at that point is internal to wordpress.
Thanks in advance!!
the path information can be obtained from normal php functions like pathinfo() and realpath() for example .
Bit too late to the party but I think what you are asking for is to find the source of the document in the clients system and based on that you want similar files there to be picked up by the browser and then sent to the user.
I think it will be a fairly complex thing to do, firstly you have to get the source of the document being added to the browser (I am not sure it can be done, but if it can be done then it will be via javascript) and then upload all the files one by one to the server hosting wordpress and you can do this by creating a custom page which will add the files uploaded to it as a wordpress attachment and then using something like jquery file uploader to upload files to that location.
But honestly, I think it would be a very complex thing, unless the client and the server are on the same machine.

where does drupal save images when you use cck and imagecache?

I am thinking in moving all JS and images from webserver to another server to mitigate the load on my webserver. then i will use parallel module to get this stuff from the other server.
now, currently i am using cck and imagecache modules. and i dont know where does drupal save the images.
i checked mysql (files table) and found something like this
Mysql>select filepath from files limit 2;
sites/default/files/2010413132344592734_2.jpg
sites/default/files/2010491910913580_5.jpg
i checked for such files but i didnt find anything like this in this directory!!
i inspected one of the images in one of my articles and found that this image is in one of the cache folders that have been generated automatically by imagecache module. i tried to delete this image from server and refreshed my page, imagecache recreated it.
now where did imagecach get this image from? where does drupal save my images??
Thanks for your help
Imagecache takes source images from whatever path is set in the files table, which is generally sites/default/files, the directory you listed. Your imagecache directory was within that directory, right? I think your files are probably in that directory and you just missed them for some reason. Directory listing cached in your FTP client, maybe?
For myself, it stores everything in the sites/default/files folder.
But, some settings to look at...
The File system path setting, located at ?q=admin/settings/file-system
The path settings for the particular field. Open the settings for the particular field, and look in the File path setting in the Path Settings fieldset.
If those settings are different, your file may be somewhere else. Otherwise, it's going to be in your sites/default/files folder.
Check the following locations
[...]\htdocs\drupal\sites\default\files\field\image
[...]\htdocs\drupal\sites\default\files\styles\large\public\field\image
[...]\htdocs\drupal\sites\default\files\styles\medium\public\field\image
[...]\htdocs\drupal\sites\default\files\styles\thumbnail\public\field\image
where [...] is the location of the htdocs folder inside your webserver container.
If you are using xampp then it could be C:\xampp183\htdocs............
Hope this helps !
In the drupal database, check the table "file_managed" and the column "uri" (which gives the uri to access the file either local or remote).
You might find a value like below .. (ignore the jpg name , that is only for my setup)
public://field/image/8_mayurkotlikar_tigress5.jpg
This shows the location of the image.

Drupal: imagecache doesn't generate images

So, I have a strange issue with Drupal imagecache.
When I upload an image, the image is correctly stored in a folder, but imagecache doesn't generate the other cached images.
It doesn't work anymore after I moved the website from development server to the production environment.
The production server is IIS7.
All the "files" subfolder have both write/read permissions, imagecache module is supposed to create folders inside "files" folder.
The GD toolkit is correctly enabled (in Drupal report, imagecache module is correctly enabled). It is php 5.2.
thanks
Check out Imagecache's troubleshooting guide in the handbooks. In particular, check the logs for errors explaining where the process is breaking down.
Also, check the paths that are included in your pages and make sure they are still correct, now that you've moved the site to a production server. This issue has some more tips, specific to the path problem.
Finally, if none of that helps, check the issue queue. There are several issues related to IIS.
99% of the time when I have an issue with imagecache not creating images it has something to do with file system permissions. Verify that your web server is able to write to all of the files/imagecache directories recursively.

How to store Blobs in Drupal?

I want to store PDF and Image files in Drupal. By default Drupal seems to store binary/uploaded files into the filesystem. I want to to be able to store files so that - I can have workflows, metadata, IP information and URL aliases?
Update, am still stuck at how to create URL aliases for files on the file system. Drupal only seems to allow creating URL aliases to node content.
The simplest solution for Drupal is to use the Upload module, which is in core. The upload module allows you attach files to nodes. As you note, they are stored in the filesystem.
If you want to get more complex, you can build your own content types through the web interface by using the CCK family of modules (such as the filefield module or the imagefield module). Your files are still stored on the filesystem.
You could use CCK to create the metadata field you want.
You could use the workflow or rules modules to implement workflow.
IP information is recorded automatically by Drupal's logging module (either the database logging module, which logs to the database, or the syslog module, which logs to syslog).
URL aliases for nodes are available in core Drupal by enabling the path module (or download the pathauto module for automatic creation of aliases).
I tried Drupal's Upload module, FileField as well as uploading files using FCKEditor - I prefer the last one - it is closer to my specific scenario.
Creating an alias to the file will likely require some custom code.
It's not possible to simply create an alias using the Administer > Site building > URL aliases screen. I tried inserting a record with
insert into url_alias (src, dst) values ('sites/default/files/ChipotleArt.JPG', 'here-is-the-file.jpg');
That still didn't work. So, you will really likely need to write some custom code.

Resources