Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
I think I would move $_FILES inside the class to abstract the process a little more. And make the defaults something reasonable (e.g. maxFileSize set to the INI max size).
You are never checking if the move_uploaded_file() failed
When checking errors, I like to check every possibility to give them the full idea of what wen't wrong. As of right now, you are only returning a single error by doing elseif()'s, perhaps having them as their own conditionals.. your choice
If everything wen't well, I don't see a need for returning anything other than a boolean true.. let the developer decide what to display. Things like
I didn't have time to post any code, but agree with Jcart's comments. To allow multiple file upload you might want to move the form field name to the upload method so you could process several files:
Thanks devnetworkians
great tips and suggestions !!
As i am new to OOP your suggestions helping me a great deal.
Based on the suggestions and comments made above i am going to make a new uploader class.
Once completed i will post again in this section for your feedback.
Thaks a lot
arborint wrote:I didn't have time to post any code, but agree with Jcart's comments. To allow multiple file upload you might want to move the form field name to the upload method so you could process several files:
i just wonder why did you use rename() if you can rename the file before you upload it. in your case.. you upload it first then you rename the file. i think it will make slower.