I have a script which uploads image in a folder then then path to the database.
it works well.
the problem is that i can`t display the image using the path.

<?php
 

$sql=mysql_query("SELECT path,user,date,filename FROM picha WHERE user='peacemaker'");
		  $row = mysql_fetch_array($sql);
		  $user=$row['user'];
		  $filename=$row['filename'];
		  $path=$row['path'];//here you get path where you store image for user1
		   $date=$row['date'];

echo"<img src='$path' width=300 height=250 alt='$user'>";//here is where i want to display the photo.
?>

when you echo only the path it gives something like this.

c:/wamp/www/photo/uploads/Biboze.jpg

and i`m currently working on www folder.

So if you can help where i`m getting wrong i need your help please.

Member Avatar for diafol

Why have you got a separate filename field if the whole lot is in the path?? If I'm getting you right, you just want to take off the c:/wamp/www bit? Well you should make the path usable through the upload and update/insert into db script. What's your upload function?

i decided to test it on my server but nothing changed,it can upload the file and save the file path but i can`t display the path.
here is the upload Code.

<?php
 include"config.php";
//edit this
$_max_file_size = '3000000'; //file size in bytes.
$upload_dir = "/home/maselaco/public_html/photo/uploads/";

$_i = "1"; //number of files to upload at one time
//end edit

echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
echo "<form enctype='multipart/form-data' action='?do=upload' method='post' style=\"margin: 0px;\">";

echo "<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='" . $_max_file_size , "'></td></tr>";
if($_GET['do'] != 'upload')
{
echo "<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
echo "<tr><td class=bodytext>Choose your image:<br>";
//show number of files to select
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value=\"Upload Photo\" style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
}

if($_GET['do'] == 'upload')
{
//upload all the fields until done
For($i=0; $i <= $_i-1; $i++)
{
//file with the upload folder
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
//actual file name with the random number
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);
//do not upload the 'left blank' fields
if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
//uploaded successfuly
$_uploaded=1;
}
else
{
//error uploading
$_error=1;
}
}
else
{
$_check=$_check+1;
}

}

//file(s) did upload
if($_uploaded == '1')
{
$_uploaded=0;
$adID = $_GET['adID'];

 $result=mysql_query("update picha set path= '".$target_path."',user='kimui' WHERE user='kimui' ");
 if($result){
 echo"You uploaded your image successfully";
 
 }

}
//file uploaded?
if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}
//user selected a file?
if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>
</table>
 Down here i`m trying to view the file i uploaded.
Help pliz



<?php

$sql=mysql_query("SELECT path,user,date,filename FROM picha WHERE user='kimui'");
		  $row = mysql_fetch_array($sql);
		  $user=$row['user'];
		  //$filename=$row['filename'];
		  $path=$row['path'];//here you get path where you store image for user1
		   //$date=$row['date'];
		   echo"<img src='$path' width=300 height=250 alt='$user'><br> $path";
		   
		   
		   ?>
Member Avatar for diafol

What does this give?

$result=mysql_query("update picha set path= '".$target_path."',user='kimui' WHERE user='kimui' ");
 if($result){
 echo"You uploaded your image successfully";

Do you get the msg? You're updating, but is there a record to update? should you check to see if there is a record first, then 'update' if there is, 'insert into' of there isn't.

??

yes i`m getting the msg!i inserted the recorcd through PhpMyAdmin but only the field of user.
And after updating i got somthing like this in the path field
/home/maselaco/public_html/photo/uploads/Biboze.jpg
in the path field i used VARCHAR(100)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.