CodeIgniter Forums

Full Version: Segments not working with file upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]marss[/eluser]
Hi,

I'm trying to send some arguments when making a file upload, my uploadscript is a copy of the example over at http://ellislab.com/codeigniter/user-gui...ading.html

So I added two arguments:
Code:
<?php echo form_open_multipart('upload/do_upload/9/8');?>

But these two never shows up in my controller - they are output in the HTML before submitting form though.

Code:
$this->uri->segment(3)
returns nothing. I even tried looking at
Code:
$_SERVER['REQUEST_URI']
but it's actually missing there as well - but segment(1) and (2) works.. also shows up in REQUEST_URI.

Any ideas on why I don't recieve my /9/8?

Thankfull for any input!

El Forum

[eluser]InsiteFX[/eluser]
Thats the controller and function that it will post and I know you do not have function 8 or 9 in your controller.

Maybe if you explain what you are trying to do we can help you.

El Forum

[eluser]marss[/eluser]
[quote author="InsiteFX" date="1338311068"]Thats the controller and function that it will post and I know you do not have function 8 or 9 in your controller.

Maybe if you explain what you are trying to do we can help you.
[/quote]

I wish to tag my uploads with a number. In this case the uploaded file would be tagged in the database with typeA = 8, typeB = 9. As I cannot add any extra field in the upload form since it contains a input type="file" I figured the best approach would be if I could just add my arguments in the <form action="">.

Thanks for your reply.

El Forum

[eluser]CroNiX[/eluser]
just send them as hidden form fields

El Forum

[eluser]marss[/eluser]
[quote author="CroNiX" date="1338330045"]just send them as hidden form fields[/quote]

Unfortunately that doesn't work when having a <input type="file"> from what I understood (?). Because in the controller I can only access $_FILES and $_POST is empty.

For now I will have to return the uploadId on upload success and update my fields in the database with ajax I guess.

El Forum

[eluser]LuckyFella73[/eluser]
Quote:Unfortunately that doesn’t work when having a <input type=“file”> from what I understood (?).

That is not right. You can have all types of input fields in your form.
Having a form element type:file does not restrict you in any way to use
other form fields!

So do it like Cronix said and use hidden input fields!

El Forum

[eluser]CroNiX[/eluser]
You should be able to send any form element in a form. The only difference is how you access them on the server end. Files will always be in $_FILES and all other post data will be in $_GET or $_POST, depending on how you sent your form.