Jump to content

Issues with InputfieldFile not working through API


Recommended Posts

I'm currently making a module that upload/save a csv... Am I missing something? I'm having some difficulties getting this to work.

$this->setFuel('processHeadline', "Import Programs");
$form = $this->modules->get("InputfieldForm");
$form->method = 'post';
$form->action = '../save/';

$field = $this->modules->get("InputfieldFile");
$field->name = 'file';
$field->label = 'Upload Program CSV';
$field->extensions = 'jpg png csv';
$field->maxFiles = 1;
// $field->overwrite = true;
// $field->required = true;
$field->description = "Convert spreadsheets to CSV (Comma delimited) (*.csv) before uploading";
// $field->maxFileSize = 200000;
$field->destinationPath = "./csv/";
// $field->type = 'file';		

$field = $this->modules->get("InputfieldButton");
$field->type = 'submit';
$field->value = 'Upload CSV';

return $form->render();

I'm mimicking some code snippets from "Import Pages From CSV module" and that doesn't seem to be working either... so it kind of leads me to believe it could be an environment issue or processwire version.  I also don't see any JS errors. Though when making fields through the backend/gui it seems to be working fine.

What I'm expecting...

What I'm actually experiencing...

ProcessWire 3.0.39
PHP 7.0

Jason Huck explains the exact problem/situation I'm having.


I have a very similar situation. I'm trying to upload a CSV file to a custom admin page, created with the Admin Custom Pages module. I've constructed a simple form using the API. When I load the page, the form appears to render correctly, but it doesn't appear to be working 100% correctly.

• Drag and drop isn't working. The browser just offers to open the dragged file. There are no JS errors in the console and it looks as if all the required JS assets are included on the page. If I instead click the "Choose File" button and select a file, it does appear to select a file (if I hover over the "Choose File" button, it displays the selected filename).

• Submitting the form does upload the file, though overwrite isn't working. I get the following error when trying to re-upload the same file:

"Refused file [my filename] because it is already on the file system and owned by a different field."


@source https://processwire.com/talk/topic/12986-file-upload-via-inputfieldfile/#comment-125240


Link to comment
Share on other sites

Sorry I mis-spoke. The ajax bug is still appearing on pw3.0 but the file seems to be saving properly after submiting/post. I did run into a weird error. Saying the file already exist. and I had to add $csvFile->rename("data.csv"); when processing the form.

The module I'm making is for a 2.5 pw. I was just dabbling around in 3.0. I hadn't had any problems in older ver. of pw.

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

  • Recently Browsing   0 members

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