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
https://forums.phpfreaks.com/topic/45676-text-and-images/
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
https://forums.phpfreaks.com/topic/45676-text-and-images/#findComment-221868
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
https://forums.phpfreaks.com/topic/45676-text-and-images/#findComment-221872
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
https://forums.phpfreaks.com/topic/45676-text-and-images/#findComment-221873
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.