
April 24th, 2007, 01:25 AM
|
|
Contributing User
|
|
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 67
Time spent in forums: 1 Day 2 h 22 m 42 sec
Reputation Power: 4
|
|
|
Uploading images into MySQL issues
Hi everyone, not sure if you can help me here, but I'm trying to upload multiple images into the one table in MySQL, here's the code I'm using to insert the form into the dbase:
Code:
<?php
require( "dbconn.php" );
$date = $_POST['day'] . ' ' . $_POST['month'] . ' ' . $_POST['year'];
if ($_FILES){
$image_types = Array ("image/bmp", "image/jpeg", "image/pjpeg", "image/gif", "image/x-png");
if( array_key_exists( 'article', $_POST ) ){
$insertQuery = "INSERT INTO `sn_articles` ( `id`, `date` , `header`, `writer` , `alias` , `photo_1`, `photo_1_type`, `photo_1_size`, `photo_1_name`, `photo_2`, `photo_2_type`, `photo_2_size`, `photo_2_name`, `photo_thumb`, `photo_thumb_type`, `photo_thumb_size`, `photo_thumb_name`, `featured`, `article` )
VALUES ( '" . $_POST["id"] . "',
'" . $date . "',
'" . $_POST["header"] . "',
'" . $_POST["writer"] . "',
'" . $_POST["alias"] . "',
'" . $_FILES["photo_1"]["type"] . "',
'" . addslashes (fread (fopen ($_FILES["photo_1"]["tmp_name"], "r"), filesize ($_FILES["photo_1"]["tmp_name"]))) . "',
'" . $_FILES["photo_1"]["size"] . "',
'" . $_FILES["photo_1"]["name"] . "',
'" . $_FILES["photo_2"]["type"] . "',
'" . addslashes (fread (fopen ($_FILES["photo_2"]["tmp_name"], "r"), filesize ($_FILES["photo_2"]["tmp_name"]))) . "',
'" . $_FILES["photo_2"]["size"] . "',
'" . $_FILES["photo_2"]["name"] . "',
'" . $_FILES["photo_thumb"]["type"] . "',
'" . addslashes (fread (fopen ($_FILES["photo_thumb"]["tmp_name"], "r"), filesize ($_FILES["photo_thumb"]["tmp_name"]))) . "',
'" . $_FILES["photo_thumb"]["size"] . "',
'" . $_FILES["photo_thumb"]["name"] . "',
'" . $_POST["featured"] . "',
'" . $_POST["article"] . "' )";
$result = mysql_query( $insertQuery ) or die( mysql_error() );
$submitted = '<p align="center"><strong>Your article has been submitted sucessfully!</strong></p><p><a href="javascript:history.back()">Back</a></p><p><strong><a href="admin.php">Admin Main</a></strong> | <strong><a href="logout.php">Logout</a></strong></p>';
}
}
?>
And this is the php file I'm using to display the image (well one of them)
Code:
<?php
require_once( "admin/dbconn.php" );
$sql = "SELECT * FROM `sn_articles` WHERE `id` = ".$_GET['id'] ." " ;
$result = mysql_query ($sql);
if (mysql_num_rows($result)>0) {
$row = mysql_fetch_array ($result);
$photo_1_type = $row["photo_1_type"];
$photo_1 = $row["photo_1"];
Header ("Content-type: $photo_1");
print $photo_1;
}
?>
I'm not sure what i've done wrong, but in my dbase under say photo_1_type it's saying "ÿØÿàJFIFddÿìDuckydÿîAdobed" instead of "image/jpeg"
Could someone have a quick look at my code and let me know if I've done something wrong?
Thanks! 
|