Jump to content

Recommended Posts

Hey,

 

Im trying to make pictures display from the server but all im getting back is a broken picture, the folder is on 755 and i've tried 777 but neither work. Also I can right click on the broken image, click on view image and I can view it in the 'index of uploads' here's the code for the query and how im calling it.

 


$conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '****';
mysql_select_db($dbname);


$image_viewer = "SELECT * FROM table WHERE email='$_SESSION[email]'";

$show_image = mysql_query($image_viewer);

 

im then calling it in my HTML

 

	while($info = mysql_fetch_array( $show_image ))
{


echo "<img src=/uploads".$info['uploadedfile'] ."> <br>";
echo "<b>Name:</b> ".$info['name'] . "<br> "; 

}

 

Cheers

Ye it took me to the file directory and listed the images

That's not what you were asked to check as the result of doing that. You were asked to check if the path and the filename is correct. Based on the results, there is no filename present and that would either indicate that $info['uploadedfile'] contains nothing or it does not exist because the column is actually named something else.

 

 

Ok that was the problem thank you :)

 

Although the pictures are displaying now, its the same picture, so img2 will display the same image as img1 (the last upload changes all other pictures to the latest one but the file names stay the same). heres my upload and the method im using to call the pictures from the database and server:-

 


$conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '****';
mysql_select_db($dbname);

{
$target_path = "uploads/";


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pic = ($_FILES['uploadedfile']['name']);


mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')");


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
   " has been uploaded to" . $target_path;
} else{
    echo "There was an error uploading the file, please try again!";
}


$image_viewer = "SELECT * FROM img WHERE email='$_SESSION[email]'";

$show_image = mysql_query($image_viewer);

mysql_close($conn2)

 

This is where im calling the pictures from the server and database

 



		while($info = mysql_fetch_array( $show_image ))
{

//Outputs the images

echo "<img src=/uploads/$pic".$info['uploadedfile'] ."> <br>";
echo "<b>Name:</b> ".$info['name'] . "<br> "; 

}


 

Thanks again

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.