anatak Posted December 8, 2007 Share Posted December 8, 2007 Hello, I am thinking about writing a class to let users upload pictures. I would like to try this in OO I have been thinking a bit about what my class would have to do and now I am getting more and more doubts. the functionality would be to upload a picture and resize it so that it does not break the layout of the page. would it be best to write a separate upload class and a separate resize class or would you put everything together ? things that I thought about that the code need to do. -check if the file is a picture -get the extension of the file when it is a picture -check if the target directory exist -create the target directory if it does not exist -check if the file already exists -if the file already exist then the old file should be overwritten -upload to a temporary directory -get the filesize -resize the file -write the resized file to the target directory. Is there something I have forgotten that I should do ? Any ideas about how you would start with this ? Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/ Share on other sites More sharing options...
deadimp Posted December 9, 2007 Share Posted December 9, 2007 It depends on your long-term goals, I guess. If you plan on having your library be modular, you might want to look into separating your resize code from your direct media-management code. Honestly, just uploading/resizing your pictures shouldn't be the main part of your worry. The hardest part is the higher-level stuff, such as how to manage your directories and the different situations that arise from that. -upload to a temporary directory That's already done by PHP/your server. Uploaded files are placed in the temporary folders designated in the PHP/server configuration. If you're caught up mainly on design, I'd say just go for it. Usually as you go along you'll begin to realize better methods for doing things, and if your project is realitively small and you don't have a strong 'connection' to your existing design it should be easy to revise. Note that this probably isn't the best method for 'industrial' coding, but works really well from a learning standpoint. Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-410055 Share on other sites More sharing options...
anatak Posted December 11, 2007 Author Share Posted December 11, 2007 I have been thinking about what you say. I think I will make two classes one for uploading files one for resizing pictures the pictures are part of profiles or articles. every profile will have a different folder (folder name is the userid) every article will have a different folder (folder name is the articleid) does that seem like a good idea or do you see any problems with that ? I guess that php can delete folders. Does the folder to be deleted have to be empty ? anatak Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-411497 Share on other sites More sharing options...
deadimp Posted January 5, 2008 Share Posted January 5, 2008 Yes, the folders have to be empty to be deleted. Usually you use a recursive delete function to go through the whole folder first, delete everything inside it, and then delete the folder, using rmdir(). Be sure you limit the domain of that function, though! As for giving each individual item a folder, I'm not so sure that'd be a good idea. Unless there's a massive amount of data that goes with each item, it'd be better to make the storage a little more flat. Look into a simple database structure that you can use. Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-430887 Share on other sites More sharing options...
Xeoncross Posted January 7, 2008 Share Posted January 7, 2008 If you wait about a month you can use the free one I built for http://codexplorer.com. Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-432309 Share on other sites More sharing options...
anatak Posted January 8, 2008 Author Share Posted January 8, 2008 Hey Xeoncross, Waiting for a month will not be a problem since my laptop crashed and I have to wait for spare parts. Can you please post a message in this thread when you have finished it ? thank you very much. anatak Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-433209 Share on other sites More sharing options...
Xeoncross Posted January 9, 2008 Share Posted January 9, 2008 no problem. Actually, I plan on having the fine people here give my system a good look over - So I either way you can't miss it. Quote Link to comment https://forums.phpfreaks.com/topic/80747-picture-upload-resize-class/#findComment-434175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.