How to use $formFieldName in web receive

104 views
Skip to first unread message

Sebastien

unread,
Aug 23, 2017, 2:01:22 PM8/23/17
to Fat-Free Framework
Hi,

I built a page to manage all image details of a photo gallery (title, desc, keywords, delete, etc.). For each image, there is a file input to allow to replace the image. Obviously, each file input name is unique.

So, if the page displays 15 images, I might want to replace only two of thoses.

When I loop over all images, I thought I could simply call $web->receive by passing the file input name ($formFieldName), but whatever I pass to this variable, the receive function uploads everything.

So, how I can use the parameter $formFieldName to upload only the file from this input name, then do the same for other submitted files?

Thanks

ikkez

unread,
Aug 23, 2017, 4:40:02 PM8/23/17
to Fat-Free Framework
The receive function always uploads everything.. in fact PHP accepts the file upload and the Web->receive method is used to fetch the data from the php tmp/ folder and move the files to your UPLOAD destination.
The $formFieldName variable contains the input name attribute value that was used to send the file IF it was send as multipart/form-data encoded steam.
You can use the value of that variable to make some assumptions of it's destination path, validation rules, etc. If you don't want that file at all, return false in that function.. if it's okay, return true.
In case it was uploaded by a PUT request (this could depend on your frontend solution, i.e. ajax uploader), the $formFieldName variable is always empty, because there's no form data being send for that matter and you maybe need to change the ajax uploader configuration or chose a unique upload route.

All other file operations probably has to be made afterwards using the array that is returned by the upload method `$files = $web->receive`.
If that doesn't help you much, maybe show us some code you've used, so we can understand it better.

Sebastien

unread,
Aug 23, 2017, 8:55:04 PM8/23/17
to Fat-Free Framework
Thanks for the information.

That being said, now I'm using $_FILES['file input name that contain the image ID']['name'] to get the new file name and I verify in variable $files (from web->receive) if the new submitted file has been uploaded successfully, and then update the DB with new file name.
Reply all
Reply to author
Forward
0 new messages