sshrop Posted July 9, 2008 Share Posted July 9, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/113859-how-to-make-a-photo-appear-on-a-page-after-being-uploaded/ Share on other sites More sharing options...
budimir Posted July 9, 2008 Share Posted July 9, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/113859-how-to-make-a-photo-appear-on-a-page-after-being-uploaded/#findComment-585097 Share on other sites More sharing options...
Third_Degree Posted July 9, 2008 Share Posted July 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113859-how-to-make-a-photo-appear-on-a-page-after-being-uploaded/#findComment-585103 Share on other sites More sharing options...
NeilsPHP Posted July 9, 2008 Share Posted July 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/113859-how-to-make-a-photo-appear-on-a-page-after-being-uploaded/#findComment-585604 Share on other sites More sharing options...
Third_Degree Posted July 9, 2008 Share Posted July 9, 2008 NeilsPHP you never defined the variable $name Quote Link to comment https://forums.phpfreaks.com/topic/113859-how-to-make-a-photo-appear-on-a-page-after-being-uploaded/#findComment-585644 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.