forumnz Posted April 5, 2007 Share Posted April 5, 2007 Ok, I need to write a script but I have no idea how to go about it. This is what needs to happen: Person goes to upload.php. Person browses their comp. and selects images. Person writes a code (bout 5 chars long) next to each image. Person clicks upload. Another person goes to images.php and automatically every image uploaded to a specific directory is displayed along with its unique number below it. How can I go about this? Sam. Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 5, 2007 Share Posted April 5, 2007 Very simple example - but it's a place to start: http://php.about.com/od/advancedphp/ss/php_file_upload.htm Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 Person writes a code (bout 5 chars long) next to each image. Clear this ?????? Quote Link to comment Share on other sites More sharing options...
forumnz Posted April 5, 2007 Author Share Posted April 5, 2007 I mean like a special code that identifies that image. So code might be cri_123 and that would be specific to a certain image. Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 5, 2007 Share Posted April 5, 2007 You mean like an image name - in that case, you should set the file to save as that name also - so if image1.jpg is named as Photo_2 - it will save as Photo_2.jpg. Also make sure to have it check to see if the image "code" is taken already. Quote Link to comment Share on other sites More sharing options...
Fergusfer Posted April 5, 2007 Share Posted April 5, 2007 A cheap and cheerful way to do this is to use the uniqid() function to generate, um, well, a unique ID. Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 5, 2007 Share Posted April 5, 2007 But do you want it as an ID - or as a "title"? Do you want images named as "01040194" or "My_Kids" Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 View attached script I think this may help you abt 50%. By the way the script is for image resize. but also have some validations you need. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
forumnz Posted April 5, 2007 Author Share Posted April 5, 2007 I basically just want each image to have its own unique code. I like the first idea. Now how would i get it to pull all the images from a directory and display them? Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 5, 2007 Share Posted April 5, 2007 The way I'd do it is when uploaded - store the name in a database (but be sure to give the uploaded image that same name - then run a query which pulls all names and displays as the following: <?php foreach ($page['name'] as $z) { echo '<img src="', $z['name'], '.jpg">', $z['name'], '</br>'; } ?> Of course there is more to it - but in terms of displaying them, that is the basics. Quote Link to comment Share on other sites More sharing options...
forumnz Posted April 5, 2007 Author Share Posted April 5, 2007 Wow I am officially confused. Help? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 5, 2007 Share Posted April 5, 2007 I basically just want each image to have its own unique code. I like the first idea. Now how would i get it to pull all the images from a directory and display them? ------------------------------------------------------------------ <?php foreach (glob("imagedir/*.*") as $filename) { echo "<img src=\"".$filename ."\">"; } ?> Quote Link to comment Share on other sites More sharing options...
JSHINER Posted April 5, 2007 Share Posted April 5, 2007 Step 1) Create your "upload" page which will: a) allow a user to choose a file from their computer b) have a field to name the file - "name" field c) upload that file - giving it the name of the "name" field d) write the "name" field to a database Step 2) Create the "view" page: a) Run a query on your "names" database and pull "names" from it. Example: SELECT name FROM names_database b) Use this to display the images / names: <?php foreach ($page['name'] as $z) { echo '<img src="', $z['name'], '.jpg">', $z['name'], '</br>'; } ?> Enjoy! P.S. - Be careful when allowing users to upload images - make sure you set the extension to only allow .jpg / .gif - also, file size may be an issue if you are on a shared server. Quote Link to comment 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.