Jump to content

Broken image when showing from MySQL


TiiTii

Recommended Posts

Hey there!
 
I have this big project due 5 days and I really need some help. I've made a imagesharing website where you upload images to a MySQL database into a table called images (with id, name and image)
 
This is the uploading form code:

 

<form action="laddaupp.html" method="POST" enctype="multipart/form-data">    <p> Ladda upp här </p>    <input type="file" name="image" /> <input type="submit" value="Ladda upp" />    </form>       <?php   define('DB_NAME','xxxxxx');   define('DB_USER','xxxxxxxxx');   define('DB_PASSWORD','xxxxxxxx');   define('DB_HOST','xxxxxxxx.com');      //Ansluta   mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error());   mysql_select_db(DB_NAME) or die (mysql_error());      $file= $_FILES['image']['tmp_name'];      if(!isset($file))    echo "Välj en bild";               else   {   $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));   $image_name = addslashes($_FILES['image']['name']);   $image_size = addslashes(getimagesize($_FILES['image']['tmp_name']));      if($image_size==FALSE)    echo "Det är ingen bild";           else   {   if(!$insert = mysql_query("INSERT INTO images VALUE ('','$image_name','$image')"))    echo "Problem med uppladdning";   else   {   $lastid = mysql_insert_id();   echo "Klart! <p /> Bilden du laddade upp: <p /> <img src=get.php?id=$lastid>";   }   }   }       ?>

 
and this is the page which I'm trying to view the images on:
     
 <?php       define('DB_NAME','xxxxxxx');   define('DB_USER','xxxxxxx');   define('DB_PASSWORD','xxxxxx');   define('DB_HOST','xxxxxxxxxxxxxx.com');   mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error());mysql_select_db(DB_NAME) or die (mysql_error()); $res=mysql_query("SELECT * FROM images");echo "<table>";while($row=mysql_fetch_array($res)){echo "<tr>";echo "<td>";?> <img src="data:image/jpeg;base64,base64_encode($row['image'])"> <?php echo "</td>";echo "<td>"; echo $row["name"]; echo "</td>";echo "</tr>";}echo "</table>";mysql_close(); ?> 

 
When I open this file I get this:
65685-pZSbl5mgk6CllZyalw-trasigabilder.p
Why do my images get broken??
 
Could someone please help me I'd be really happy!
 
 
Link to comment
https://forums.phpfreaks.com/topic/276523-broken-image-when-showing-from-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.