Jump to content

Text and Images


forumnz

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ."\">";

}

 

?>

Link to comment
Share on other sites

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.

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.