MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 24th, 2007, 01:25 AM
Souliebaby Souliebaby is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 67 Souliebaby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Uploading images into MySQL issues


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT