Jump to content

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!
 
 
Edited by TiiTii
Link to comment
https://forums.phpfreaks.com/topic/276523-broken-image-when-showing-from-mysql/
Share on other sites

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.