Hot answers tagged

44

413 errors occur when the request body is larger than the server is configured to allow. Here’s how you can fix it, depending on your web server: Apache: Set the LimitRequestBody directive in either your httpd.conf file or a local .htaccess file. (https://stackoverflow.com/a/3719358/1688568) Nginx: Set the client_max_body_size directive in nginx.conf (http:/...


7

The only thing Craft enforces is the maxUploadFileSize config setting, which by default is set to 16MB. Outside of that, any limitations you run into will be environmental/server config related.


6

Ahh, a bit of fiddling and poking around later... $file = UploadedFile::getInstanceByName('myFieldName'); $fileName = AssetsHelper::cleanAssetName($file->getName()); // Make fileName uniqueish by adding a timestamp to it. $fileParts = explode(".", $fileName); $extension = array_pop($fileParts); $fileName = join(".", $fileParts) .'_'. time() .'.'. $...


5

You shouldn't need to create a custom plugin to do that. You can easily create a Matrix content field for your carousel. Create a new block called slide. From there you can create an asset field to upload the slide image. You can render this into whatever markup you'd like (even bootstrap). As for cropping an image and converting it into a jpg, check out ...


5

You're probably using GD, which doesn't support BMP files. If you install Imagick on your server, Craft will use it automatically and it supports a much wider range of file types, including BMP files.


5

Well, after searching for this for more than 2 hours, I bumped into a working solution; Event::on( Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function(ElementEvent $event) { $asset = $event->element; if ($event->isNew && $asset instanceof craft\elements\Asset) { $newFileName = 'file-'.md5(...


4

I can confirm this is a bug on Craft 2.2.2579 when CSRF protection is enabled. Will get a fix out for it shortly and update this answer when it's done. Update: Fixed in Craft 2.2.2582.


4

I solved the problem by setting the client_max_body_size to, in my case, 20M. Did this using the following nginx_app.conf location / { # try to serve file directly, fallback to rewrite try_files $uri @rewriteapp; } location @rewriteapp { # rewrite all to index.php rewrite ^(.*)$ /index.php?p=$1 last; } location ~ ^/(index)\.php(/|$) { ...


4

Yii’s CUploadedFile class actually doesn’t support retrieving uploaded files that came from a file input whose name was “namespaced” (e.g. name="fields[handle]" rather than just name="handle"). However, Craft has its own UploadedFile class which extends CUploadedFile, and the whole point of it is to add that namespaced input name support. It uses a dot ...


4

Have you created that directory? If not, you need to. Also be sure the directory you create has the correct permissionss (writable by the web server)


4

For Craft 2, You can write a plugin that listens to the onBeforeSaveAsset event, and changes the title from the asset parameter to whatever you want. Something like: if ($event->params['isNewAsset]) { $asset = $event->params['asset'] $asset->getContent()->title = 'My New Title'; } For Craft 3, you can write a plugin that listens to the ...


4

You need to use the Update Asset Indexes tool in Settings in the control panel: Whenever there are files within your asset source that were not added directly by Craft (e.g. via FTP), you will need to tell Craft to go and look for them. You can do that from the “Update Asset Indexes” tool within Settings.


4

After some mail exchanges with Brad and Andris from Craft CMS, it turned out that there is an edge case where the image rotation on upload will not work if the EXIF extension is not installed (which was our case). There are two solutions to fix this problem: Install EXIF extension Install and use Imagick instead of GD. As Imagick is the recommended image ...


4

When determining the maximum upload file size, Craft first takes the php.ini file upload_max_filesize, post_max_size and memory_limit into account by getting the minimum value and only then applying the Craft maxUploadFileSize config setting.


4

I understand now within the context of you are using docker. Since docker creates a new file system separate from your computer's file system, you will want to run these commands on the docker instance. I do not use docker regularly, but I believe you can use docker attach while the droplet is running to access the droplet's file system. You will want to ...


3

Currently the images are being cleansed on upload, which means that they are being re-saved to make sure that no malicious code is injected in them. Unfortunately, this means that EXIF data gets stripped out along the way, but since Craft already uses PEL, it should be possible to tweak Craft a bit so that the EXIF metadata is preserved during this ...


3

This is a very old question, but thanks to this example I was able to build quickly a profile picture form using Craft 3 and jQuery File Upload plugin (thank you!). The action value and file input name have changed. You should write it like this now: <input type="hidden" name="action" value="users/save-user"> <input id="image-upload" type="file" ...


3

It looks like .key files are not included in the default allowed file extensions. But you can manually add it with the extraAllowedFileExtensions setting in your config/general.php file: 'extraAllowedFileExtensions' => 'key'


3

It looks like you're trying to access another asset within your assets (asset meta field). {% set photos = entry.photos %} {# Loop assets of `entry.photos` as `photo` #} {% for photo in photos %} {# Get first `uploadPhoto` element within `entry.photos[nth]` #} {% set image = photo.uploadPhoto.first() %} {{ image.getUrl() }} {% endfor %} I ...


3

You're not overlooking anything. What you're asking for is not a core feature of Craft and probably will never be. There's also no plugin yet that does something like this. So the only answer I can give you right now is that you have to find someone who makes such a plugin for you. The jobs board on straightupcraft.com is probably a good address to find a ...


3

Is there anything special about that PNG file? It's likely that it's in a PNG format that GD does not support. Install Imagick and try again. It handles a much wider range of formats, is generally less buggy and produces better results. Craft will automatically use it if it detects that it is installed and available to PHP.


3

I'm 99% sure the answer is yes, that's doable, although you'd need a custom plugin to handle the bulk of it. You'd need to write some PHP to handle the unzip, and place the files where you want them. You may want to create a plugin with a Controller to handle the file upload & unzip. You can use Craft's Zip::compress() and Zip::unzip() methods to help. ...


3

I was going to suggest using the very handy Import plugin, but I see that it only supports entries, categories, and users. And unfortunately, I don't see another plugin that does this specifically. But have a look at the craft plugins page in case I missed something. You might also be able to extend the Import plugin (with permission of course) to support ...


3

Does this help you? It'll let you add additional file extensions that are allowed to be uploaded. http://buildwithcraft.com/docs/config-settings#allowedFileExtensions


3

On the server, check: if the folder exists? Check the folder permissions are set to 777 (could probably reduce to 755) Within Craft: In: Settings > Assets > Asset Sources - make sure File System Path and URL fields, have no leading forward slashes e.g. imgs/logos/


3

When Assets moves files around because of dynamic Assets folder changes, it does not remove empty folders. On the surface it seems like a no-brainer - just check if the folder is empty and if so, then nuke it! But if you go deeper, it gets complicated. Should the physical folder be removed as well? If not, then the next time you index Assets, the folder ...


3

I believe you are looking for the Assets Field


3

They are uploaded to Craft first to a temporary file, then Assets uses the Asset Source to work out where to send them next - either the local file system or a remote one. For handling large uploads in general you could look at this plugin: https://superbig.co/plugins/large-upload


3

The issue lies if you have a Preparse field in that field layout, see details here: https://github.com/aelvan/Preparse-Field-Craft/issues/23


3

It doesn't seems possible natively, you should write a custom upload script. → Example #1 → Example #2 If it doesn't matter to add the images inside your rich text field, one more simple workaround could be to allow image upload to your assets using a separate upload field. → Uploading Files from Front-end Entry Forms


Only top voted, non community-wiki answers of a minimum length are eligible