Jump to content

picture upload resize class?


anatak

Recommended Posts

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 ?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.