#1
My code is here:

I am trying to get many image in a single form. For example




I wrote some code using trongate's filezone code as a reference (attached in the link). But it is only saving a single file.
My $_FILES is populated with all the files that I need, I just need to save it to modulename_pictures directory. This modulename_directory is generated when I use trongate desktop app.


Is there any function like upload_image($filename, $destination)?


Please help me fix my problems.
Thank You
#2
Hello
Could you use code and /code tags with [ ] brackets. It will make the code easier to read.
Could you post the submit method?
Thanks
#3
the link i gave contains formatted code.

submit code


Please see the link I gave. I think there you can understand what problem I am facing.
#4
I am on my phone. So it's herder on a website
What does your data array say
Json($data,true)
#5
I think form_file_select does not populate $_POST
so my $_POST contains values other than files. (Ex- username, password, etc but not file data)
But my $_FILES contains all the files that I want from my user.
$_FILES contain all the file attribute such as name, tmp_name, error=0 and filesize>0
I am able to obtain data from the user, and I am also able to save data to the database using my own code.
My problem is I don't know how to write a function that would use trongate's function (shown below) to upload multiple file to a desired module.

my $data looks like this


I just want an answer to the question below:


And I hope I am not sounding rude or anything. My English is not good and even writing this much is difficult for me. So excuse my inability to craft sentences in a manner that would not accidentally hurt one's emotion.
#6
Hi Freiza,

Don't worry you are not sounding rude at all :)

The Trongate filezone works via the API, so it is doing all the passing through JavaScript. You can find the code in trongate-filezone.js and the endpoint it is pointing to is 'Upload'

API endpoint definition in assets/api.json


which the uploader passes to the upload() method in Trongate_filezone.php


You could write a loop looking at each array element from $_FILES, checking if error was not == 0 (true) then pass each picture to the API endpoint as above
#7
Hi DaFa,
I am already using trongate_filezone's code, please see here https://wtools.io/paste-code/bE3x
I can't use ajax here to send the files to api endpoint. I have to accept all the form all together with other data value at once.
So what I am doing is


My ideas to solve this problem:
1) Write pure php code to upload files to destination directory, but then I will losing the trongate's ability to compress images and creating thumbnail
2) If there is a function that would allow me to pass both file data and the destination folder like:

3) Or you suggest something, because I have been reading this framework for only 2 days, and I just learnt PHP because I like trongate :)
Please help
#8
Hi Freiza,

Apologies, I had overlooked your link to https://wtools.io/paste-code/bE3x

Yes, you are right, no need to use ajax here, as you are already in php. There isn't a method to do as you wish, but we can borrow from filezone to create our own. I have a busy day on and about to head out for a 3 hour drive to meet up with a new client. I'll take another look at this later today and post a method to do as you wish or Dan may step in.

Cheers,
Simon
#9
No problem. I will be eagerly waiting.
#10
Hi Freiza,

The reason only one file or picture is being uploaded in the foreach loop is the upload_picture() method in Trongate.php is hard coded to look at the first file in $_FILES > line 183 of Trongate.php


to get round this I copied the upload_picture() (not a good practise as it will get replaced on a framework update)
and added a new method called upload_pictures() in Trongate.php > you could move this into a custom class and extend Trongate

Then I created a test module called Pic:

the view is a simple form like yours, with a hard coded update_id for testing


Images are uploaded to pics/assets/freizas_pics/1
and thumbs to pics/assets/freizas_pics/thumbnails/1

A bit of a hack, but you can get the gist of how it could be done.

Let me know how you get on

Cheers,
Simon