File uploads: check if any uploaded and specify filename |
[eluser]Martin Penev[/eluser]
Hi there, I'm on a upload form that should upload a file, but there are some things I haven't found yet: 1) How can I check, if a file has been uploaded? (Important if I want to program a mandatory upload field) 2) How can I specify a filename which will be used as a filename after upload? Have checked the user guide, but couldn't find any answer. Thanks for your help in advance. Martin
[eluser]mjijackson[/eluser]
To tell if the file uploaded correctly, you can use a special callback function and PHP's native is_file_uploaded function. This code is just off the top of my head (so it might need some tweaks) but it should convey what I'm talking about: In the controller: Code: function upload_page()
[eluser]BravoAlpha[/eluser]
[quote author="Martin Penev" date="1186789947"]1) How can I check, if a file has been uploaded? (Important if I want to program a mandatory upload field)[/quote] You can use the Upload class. [quote author="Martin Penev" date="1186789947"]2) How can I specify a filename which will be used as a filename after upload?[/quote] I'm trying to figure that out too. Edit: http://ellislab.com/forums/viewthread/45432/ http://ellislab.com/forums/viewthread/47491/
[eluser]Martin Penev[/eluser]
Hi guys, thanks for your replies. They have been helpful. About solving the first problem: ================================== Either use this function will do it for sure: Code: function upload_page() or you can use the error status from the $_FILES-array like this Quote:$_FILES['userfile']['error'] Solving the second problem: =========================== walesmd has brought in the right idea, just to use the rename() function. I guess I'll put it or extend it via the "File helper". I don't fancy the idea to change the upload class
[eluser]Michael Wales[/eluser]
I would definitely extend the File Helper and add in the rename function there - seems to be a great fit and I am sure you can introduce some additional functionality that could prove useful to yourself and the CI community. |
Welcome Guest, Not a member yet? Register Sign In |