Saving image names in mysql?
Currently i have system that's do resizing and creating as many images as needed and storing them on web servers file system. Also i make and entry in database of image basename in mysql. For example i upload 5 images the basename would be 372FDSC and then it will add _0, _1 etc. to each image in filesystem so it makes image look like 372FDSC_0.jpeg and so forth.
So where is my problem? It's that i cannot delete or upload new images since i don't know image name in code.
I wonder is there is some better solution to save image names for article? Like mysql row that holds all names (372FDSC_0.jpgeg;372FDSC_01.jpeg etc.) So when i delete or upload new ones i 开发者_Go百科know what filename i can use.
I hope this all makes some sense to anyone if not please say and i'll add required details.
You could use a timestamp at the end of the image name, so you're sure it's unique.
$new_name = $basename . "_" . time() . $extension;
You could use timestamp as stated above or you could also give your images descriptive names based on what the image contains instead of the 372FDSC naming.
Have 3 columns in your database table titled 'basename', 'no of images', 'article name'. Now make a loop to get all the images. eg if you have 5 images in your article 'abc'. Then you will use
for($i=0;$i<5;$i++)
$images[]=$basename.$imageno;
keeping in mind that $basename is the basename retrieved from database and same applies to $imageno.
You can use your article id field to rename images. For example, if your article id is 237, the images will be 237_1.jpg, 237_2.jpg etc.
In that case, you will not need to store image name in db also.
精彩评论