Form - File Upload

I have an upload object in my form, derived from:

{ type: "upload", name: "related-files", url: "upload/file_upload.php" }

When I select a file and click the upload arrow, it just turns red. I’m sure it’s due to my php file not capturing the upload correctly, but there is no error output to guide me. Also, the documentation for uploading files seems almost non-existent.

I copied the example php code and I am using it, but it’s just not helping. :cry:

My questions:

  • How do I upload a file so it doesn’t error out?
  • If the file uploads prior to the rest of my form being submitted, how do I connect the file to my form again when the form submits? It seems that uploading the two things separate from one another would separate them.



Do you use ‘dhtmlxform_item_upload.php’ file from the dhtmlxForm package?
php returns something like “{state: true, name:‘file_name.ext’, extra: {info: ‘just a way to send some extra data’, param: ‘some value here’}}”

  • I am not clear what you want in second question. Please can you show/attach simple example?


Yes, I’m using a dhtmlXForm upload object.

An example shouldn’t be necessary for this. I’m not looking for anyone to troubleshoot my code as much as just trying to understand what is occurring. Once I understand it, I should be able to troubleshoot my own code.

Let me try to expand on my second question:
Normally (without DHTMLX), when you submit a file in an HTML form, it sends the file along with any other form name/value pairs. So, this:


(this might not be exact syntax, but you get the idea)


Then it arrives at the formProcessor.php page as:

$_POST['userName'] $_FILES['userfile']['size']... etc...

But it arrives all together.

Using the DHTMLX uploader, you upload your file first and later you submit the form. So, where does the file go after it’s uploaded and before I submit my form? Is it held in the user session? If so, how do I get it once the form is submitted?


that’s correct, first you upload file and then submit form (if any).

  1. uplaoder have events, like onUplaodFile and onUploadFail (more events … vents.html)
  2. when file uploaded, form will contain corresponding record, you can try via getFormData()
  3. to add custom variables t upload - just append params via uploadUrl, myForm.getUploader(name).setURL(“server.php?userId=123&someParam=someVaule”)

more docs:

The params I append to the cgi call are not being seen by the post, presumably because this is a POST and not a GET. How do I either 1. tell the post where to put the file, or 2. get the file location after the POST is done?

I can’t figure out how to get that info back into my .js files.



Normally the server side has access to both GET and POST parameters sent with a file.
What kind of server are you using?