Jump to content

Recommended Posts

I am new to php and I am still learning. 

I have figured out how to let someone upload a photo to the server.  Once it is uploaded how do I get it to load onto a web page? 

For Example:

I have a house in a certain city, I upload the photo of the house;

There is a webpage that shows houses in that city. - How do I get the photo to show on that page?

Any help pointing me in the right direction will be greatly appreciated!

You can do it in many ways...

 

1.) You can call it by a name and display it in that way

2.) You can select the oldest uploaded picture with that ID and display it

 

But the best thing would that you give us some more details so we can point you to the right direction...

 

 

 

 

A code something similar to this may provide an easy solution

 

This code displays any image with the name "philadelphia" in it

 

<?php

$dir = @opendir( "/images/" );

while ( $file = readdir( $dir ) && $dir ) {
if ( eregi( "philadelphia", $file ) ) {
	print "<img src='" . $file . "' alt='Philadelphia' />";
}
}

closedir( $dir );

?>

 

Of course you could do this in a loop with names of cities from a database or based on a dynamic url e.g. http://www.site.com/houses.php?city=philadelphia

Here's how u get uploaded pic on your webpage

 

1.receive uploaded pic from tmp directory

2.store it in variable

3.upload that file on a directory on server

4.save the path to that directory in another variable

5.save this image path into database with other info about file if needed

6.when u need to recover image on webpage,use src image code just like any other image with image path above

 

here is code in brief

<? php

$fileName = $_FILES['userfile']['name'];

$tmpName  = $_FILES['userfile']['tmp_name'];

$fileSize = $_FILES['userfile']['size'];

$fileType = $_FILES['userfile']['type'];

 

$uploadDir = "/yourpath/";

      $filePath = "$uploadDir$fileName";

        if(move_uploaded_file($_FILES['userfile']['tmp_name'],($uploadDir . $fileName)))

        {               

          $query = "INSERT INTO $TABLE (name,size,type,path) VALUES       

          ('$fileName', '$fileSize', '$fileType', '$filePath')";

   

          $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

$address = "http://www.YOURFILEDIRECTORYPATH/"; //this will only work if that directory is inside WWW directory

 

$image = "$address$name";

echo "<img src = '$image' width=250,height=125/> ";///GIVE SIZE VALUE AS YOU LIKE TO BE

 

>?

 

plz consult someone about security and let me know as I am myself looking for that.

hope this helps

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.