I have in the database products, and each product has a image, I'm thinking to save image with $filename = sprintf('%08d', $id);
But for products I have also edit section, where I can change the image, which would be the best approach for changing image? It's ok if I save the new imag开发者_StackOverflowe with the old image name?
Either way. Depending on you app. If it's for example a user picture, then leave the old name as name is irrelevant but the content is important (a picture) and update a file content. If however, picture defines the content then replace the name of the image. In your case i would put the new name as image defines the content (i.e. large_image_red_productname.jpg)
Ideally, you should name the product image as a product name(i.e. product_name.jpg) regardless of what file name is uploaded.
精彩评论