![]() |
Uploading a Image
I have written a upload script and I ran into a small problem I didn't even think about. Say someone uploads logo.gif, if another person comes about and has a logo.gif they wanna upload then it already exsits. Is their anyway to add characters to the name while it is uploading so if logo.gif exsits and another person uploads that then it might generate logo1a12.gif or something? :D
|
This function will count up until it finds an empty slot. Good if you want to keep your images in order, else just generate a random file name.
Basically: Input image: myLogo.jpg If myLogo.jpg exists change to myLogo.2.jpg If myLogo.2.jpg doesn't exist, return myLogo.2.jpg PHP Code:
|
I tried what you were saying. I might not be doing it right, but its just overwritting the ones that are already upload.
PHP Code:
|
You need to get the image name from calling the function, like so:
PHP Code:
PHP Code:
|
Code:
define('DIRECTORY', 'images/'); |
No offence intended, Shane, but I really think you need to read up on how functions work. Try this resource at PHP.net. Spend a good time reading through and learning it inside-out.
Essentially you need to call the function, this is done by placing $filename = getImageName($_FILES['filetoupload']['name']) outside of the function. |
For some reason I was thinking that calling it where I did would do what I was needing. I'm very novice when it comes to php and screw up way to much! I fixed the problem by reading the tutorial and now understand 100%! Appreciate all of your help wildhoney!
|
| All times are GMT. The time now is 09:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0