Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
1-> I have php code which perfectly woks its upload the image and save the image to directory but the image is display temporary ! i want to display it permanently ... and whenever i want to change the image it will change the image and display uploaded image

here are the code
form.php

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="process.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" /><br />
    <input type="submit" name="submit" />
</form>

<?php
    if(isset($_GET["img"]))
    {
        $n=$_GET["img"];
        echo "<img src='photos/".$n."'>";
    }
?>
</body>
</html>



now uploading code

process.php

PHP
<?php


    $fn=$_FILES["file"]["name"];
    if(!empty($fn))
    {
        $res = move_uploaded_file($_FILES["file"]["tmp_name"],"photos/".$fn);
        if($res)
        {
            header("location:form.php?img=".$fn);
        }
    }
?>


SQL
this code perfectly work in my local host just create photos folder also where uploaded image will save.....

plzz help me guyz how to display the image permanently and if i want to display two image at the same time at different image how to display it !! plzz use this code and make it as i want it plzzz guyzz help me

thank you
Posted
Comments
C0DE_007 29-Jan-14 7:55am    
sorry for my bad english guyz
Kornfeld Eliyahu Peter 29-Jan-14 8:00am    
What do you mean by temporarily? Disappears after refresh? That because you add <img> tag only if you have an img value on your session...
if(isset($_GET["img"]))
That's only true after the upload...
C0DE_007 29-Jan-14 11:10am    
yes bro when i refresh the image disappears... !! i want when ever i will open the last uploaded image will display on form.php

if(isset($_GET["img"]))
{
$n=$_GET["img"];
echo "<img src='photos/".$n."'?-->";
}


i have try this code see above

can use my code which i have provided above and edit the code and send it with working code plzz
Peter Leow 29-Jan-14 8:10am    
Do you mean you want to display the uploaded image along side any existing images?
C0DE_007 29-Jan-14 11:13am    
no when i will upload any other image so existing which was showing in form it will disappears

how do you display an image alongside recently uploaded images? Almost like in a stream.
 
Share this answer
 
Comments
Member 11475444 24-Feb-15 6:07am    
Good sir you just gave me what I want. Thank you very much!
XML
image.php File:
<?PHP
$hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "username"; // change to your database password
$db_password = "password"; // change to your database password
$database = "database"; // provide your database name
$db_table = "table"; // Your Table Name where you want to Store Your Image.
# STOP HERE
####################################################################
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$uploadDir = 'images/'; //Image Upload Folder
if(isset($_POST['Submit']))
{
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO $db_table ( Image ) VALUES ('$filePath')";
mysql_query($query) or die('Error, query failed');
}
?>
image.htm File HTML Form Code:
<form name="Image" enctype="multipart/form-data" action="image.php" method="POST">
<input type="file" name="Photo" size="2000000" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png" size="26"><br/>
<INPUT type="submit" class="button" name="Submit" value=" Submit ">
&nbsp;&nbsp;<INPUT type="reset" class="button" value="Cancel">
</form>
To View Your Image File in profile.php Page:
<?PHP
$hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "username"; // change to your database password
$db_password = "password"; // change to your database password
$database = "database"; // provide your database name
$db_table = "table"; // Your Table Name where you want to Store Your Image.
# STOP HERE
####################################################################
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$query = "SELECT * FROM $db_table WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<img border=\"0\" src=\"".$row['Image']."\" width=\"102\" alt=\"Your Name\" height=\"91\">";
}
?>
 
Share this answer
 
Comments
Member 11533810 27-Mar-15 22:04pm    
? what is $username????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900