Jump to content

Interacting with the file upload field as a repeater field


tinacious
 Share

Recommended Posts

I've created a repeater field called supporting_files. In it there is a file field called file. The file field has one description field.

I am having more than one problem with this:

  1. Initially when it loads, I've set it to show 3 but it doesn't show any. When I click "Add" it tells me I have to save to be able to use it.
  2. I cannot seem to upload a PPTX file, although maybe it's just huge and not not responding. Normally it tells me the progress for images but for files it doesn't seem to so there's no way of telling if it's uploaded successfully.
  3. How do I grab this information?

I've tried to grab it like this:

<?php
if($page->supporting_files) {
foreach($page->supporting_files as $file) {
echo $file->file->url;  // this shows the path to the folder where the file is but not the file's URL
echo $file->file->description;  // this doesn't show anything
}
} ?>

Unfortunately that doesn't work. From what I remember this is how I've interacted with image fields and repeater fields, though I've had problems with the repeater field before (but it has been updated and fixed since then). I haven't tried interacting with single file fields yet so I'm not sure if it's the file field that's the problem.

It uploads to the file system just fine, I see it there, but how do I grab the URL and description?

This also only outputs 1 line when I have 4 files uploaded though only the PDF seemed to have successfully uploaded, the PNG, SWF and PPT did not—I was just grabbing random files.

It outputs the path to the folder the file is in on the file system but it doesn't get the complete path.

In the screenshot you'll see just one file but I've tried it with many.

So essentially, $file->file->url outputs the folder it's in and it only grabs 1 of 4 files.

If you need more info to help me, let me know.

Thanks.

post-466-0-43510200-1353623222_thumb.png

Link to comment
Share on other sites

I'm having trouble figuring out why would a repeater be needed here? A plain file field allows you to upload multiple files with descriptions - do you need something more? Maybe I just didn't get it. :)

If you've got field "files", you can iterate files in it like this:

foreach($page->files as $file) {
 echo $file->url;
 echo $file->description;
}

So almost what you already had there.

Then, check Setup -> Fields -> "files" -> Details -> Valid file extensions to see which types of files are accepted by your field - that setting might explain why certain files are rejected.

I hope this helps.

  • Like 1
Link to comment
Share on other sites

OH I was just being super redundant trying to make the file field a repeater when it already had that functionality. Duh. Thanks nik!

Unfortunately I'm still having problems uploading PPT and PPTX files. They are well under the allowed file size. Even zipping them doesn't make this happen. Has anyone else had this experience?

Link to comment
Share on other sites

Then, check Setup -> Fields -> "files" -> Details -> Valid file extensions to see which types of files are accepted by your field - that setting might explain why certain files are rejected.

Did you check the above tip from Nik? ppt and pptx are not in allowed file types by default.

Link to comment
Share on other sites

Yep. I added them in myself. I've attached a screenshot. All the other file formats I've added have been uploaded successfully just not PPT or PPTX.

I get stuck at this 100% page forever and the description field never appears. Also if I save it doesn't upload either. It doesn't work if I zip it either.

Uploaded successfully: swf, png, jpg, pdf, doc, docx

xpmyxs.jpg

Link to comment
Share on other sites

The file size shown for Sample.pptx is pretty large. You may need to bump up PHP's memory_limit. Can you tell what the memory limit is currently? One way to see it is to upload a PHP file to your server that has this:

<?php phpinfo();

Then view the URL in your browser and locate the PHP ini settings. You should see a line that refers to memory limit. You want this to be 128 or higher. I have mine set at 256.

  • Like 1
Link to comment
Share on other sites

I will check the machine for this project when I'm in later this week to see what the memory limit.

My home machine is at 128 but I've adjusted it since its default, which I can't remember off-hand. Both my home machine and the machine for this project use MAMP. I will check the limits for the other one later this week and keep you posted. Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...