TiiTii Posted April 4, 2013 Share Posted April 4, 2013 (edited) 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: Why do my images get broken?? Could someone please help me I'd be really happy! Edited April 4, 2013 by TiiTii Quote Link to comment https://forums.phpfreaks.com/topic/276523-broken-image-when-showing-from-mysql/ Share on other sites More sharing options...
Technocrat Posted April 4, 2013 Share Posted April 4, 2013 What are you storing the images in? Quote Link to comment https://forums.phpfreaks.com/topic/276523-broken-image-when-showing-from-mysql/#findComment-1422888 Share on other sites More sharing options...
TiiTii Posted April 4, 2013 Author Share Posted April 4, 2013 In a Mysql database in a table called images Quote Link to comment https://forums.phpfreaks.com/topic/276523-broken-image-when-showing-from-mysql/#findComment-1422948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.