File uploads: check if any uploaded and specify filename - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: File uploads: check if any uploaded and specify filename (/showthread.php?tid=2532) |
File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [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 File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [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() File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [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/ File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [eluser]Michael Wales[/eluser] Using the File Uploading Class return the current filename of the file on the server ($this->upload->data()). Then use PHP's rename() function to rename it to what you want. File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [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 File uploads: check if any uploaded and specify filename - El Forum - 08-10-2007 [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. |