Hot answers tagged

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() .'.'. $...


4

You can use the getFootHtml function to tell Craft where to output HTML queued up with includeJsFile and includeJs. You'd normally have that tag somewhere at the end of your <body>. But all it does is to get all queued up HTML and output it, so if your JS are already "included", you can use it in <head>. Another thing you could do is to not use ...


3

I would first check if you actually set up the Field handles you are currently using in your template: Matrix Field handle: 'contentPrimary' Block Type handle: 'widget' Entries Field handle: 'widgetPrimary' Assets Field handle: 'widgets' Then try to use the first() method instead of direct access to the array. Or use direct access only after adding find()...


3

You can write a plugin that listens to the onSaveEntry event. When that event fires, you can grab any of the data you need for the text file from any of the custom fields and your plugin can write it out to the filesystem at whatever place it needs for JW Player to consume.


2

is there a way to check the site for missing file links, including those in redactor? I can't think of a way to do this outside of writing a custom plugin/PHP script that loaded everywhere an Asset field might exist on an install, grabbed its contents and verified them against the file system. Additionally, it would have to load any Rich Text field you ...


2

The problem with putting them in your templates folder is now PHP/Craft is going to try and serve them. Meaning that you've got the overhead of PHP and Craft when trying to request every single asset instead of if they were in the public folder where Apache can instantly serve them (orders of magnitude faster).


2

For the record, the issue, as determined from the comments above was that the Asset field settings did not allow the type of file that was being uploaded. Updating the Asset field settings to allow the uploaded file type solved the issue.


2

You can queue files with includeJsFile, includeJs and output getFootHtml() anywhere on your page. Once you've called getFootHtml() the queue will be cleared allowing you to use includeJsFile again later in your template i.e. both in the head and body. This doesn't appear in the documentation.


2

An alternative to using a plugin to write an actual text file to the local filesystem is to create a dynamic route that looks like your entry URL format, except with .txt at the end (e.g. news/{slug}.txt), and point that route to a template called text.html or the like. Inside the text.html template, you'll need to pull the entry using the slug token: {%- ...


2

You can always check the craft_assetfolders table in the database, find the folder name you're looking for and grab its id. And it's probably just a typo in your original code, you're setting the folder ID to a variable named folder_id, but you're passing id into .folderId(id).


2

There appears to be 2 errors in your code. name="uploadPhotos.handle[]" should be name="uploadPhotos[]", assuming your field name is uploadPhotos. The handle part is unnecessary, unless you were using it like name="{{ uploadPhotos.handle }}[]", but it's redundant since you already are calling the handle to get the handle (but makes more sense when you're ...


2

Cant you just use preg_replace("/[^A-Za-z0-9 ]/", '', $stuff) for this? Seems that will strip away anything that isnt a number or a letter from the english alphabet? EDIT --------- Challenge accepted ;) public function modifyAssetFilename($filename){ return preg_replace("/[^A-Za-z0-9-]/", '', $filename); } Something according to the above strips out ...


2

Figured out what my problem was: I was trying to submit the form via Ajax, that's why the submit button is set to input type="button" I changed the submit button to input type="submit" & it worked. Not 100% sure how to make it work with Ajax but pretty sure it has something to do with the way the data is serialized. I don't really need Ajax submission ...


2

Sprout forms has hooks you can latch on to in your own custom module/plugin, so when a form is saved you can grab the asset and re-name at that point.


1

Solved it by just serving the file within a controller action like this: public function actionCacheCraftServiceWorker () { $serviceWorkerFile = Craft::getAlias('@skayo/cachecraft/assetbundles/cachecraft/dist/js/CacheCraftServiceWorker.min.js'); return Craft::$app->getResponse()->sendFile( $serviceWorkerFile, '...


1

Okay, so it turns out my file watcher (WebStorm) was the cause. It compiled the dashboard.scss, so I simply changed the Scope to make sure it only compiled my own files.


1

That field accepts any valid Twig code, so something like this should work: challenges/{{ craft.request.getPost('challenge_id') }}/ Fair warning, though... I'd also be wary of accepting untrusted front-end input like this that ends up on the file system.


1

You'll get that message whenever Craft/PHP can't upload the file (for any number of reasons). Looks like you've covered permissions and some common php.ini environmental limitations. If it's happening of every file regardless of file type or size, you can probably rule out any GD or Imagick related bug. Other things to check for: You're out of disk space ...


1

You could create a simple plugin with Pluginfactory and copy the two function I'll give you to create the URL you like Go to the page, turn on the light switch for "Controller" but leave the name blank, download it, copy it to craft/app/plugins/ Include this function to your plugins main file. If you did not disable preview/example code in the page you'll ...


1

You could setup a template at /menu that grabs the PDF you want and redirects with a 302 (not a 301 since it isn't permanent). The URL would change, but that might be ok if you only care about having an easy link to share. If redirecting is a deal breaker, you could make a small plugin that returns the file with proper headings, then call that from the /...


1

Okay - have managed to resolve this. Needed to reset the auto increment value in the craft_elements to greater than the max(id) for the craft_assetfiles - not sure how those got out of synch but that seems to have resolved it. Hallelujah!


1

Here is the solution I came up with. Hope this can help someone else. Thank you all for your suggestions, too! {% switch block.type %} {% case "text" %} {{ block.text }} {% case "widget" %} {% include "widgets/primary/"~ block.widgetFile[0].widgetPrimary[0].filename ~"" %} {% endswitch %}


1

You're problem is with 'block.entry[0].widgets', which I suspect is a typo. Try this. {% case "widget" %} {% if block.widgetPrimary|length %} {% if block.widgetPrimary[0].widgets|length %} {{ block.widgetPrimary[0].widgets[0].filename }} {% endif %} {% endif %} Also, be careful of combining conditionals where the second ...


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