Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Traxus  
#1 Posted : Friday, September 9, 2011 8:54:19 AM(UTC)
Traxus

Rank: Newbie

Groups: Member
Joined: 9/9/2011(UTC)
Posts: 6

Was thanked: 1 time(s) in 1 post(s)
Is there any documentation on how to upload multiple images straight to a mySQL database as a BLOB?
Dmitry.Obukhov  
#2 Posted : Friday, September 9, 2011 10:28:55 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups:
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Nicolas,

Unfortunately, we do not have the documentation which describes this process. However, the idea is simple. You just upload your files to some page where is placed server-side script allowing to parse HTTP POST request. You get necessary fields from POST request and save them to mySQL database.

Samples of the server-side script are in the Saving Uploaded Files in PHP.
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
Traxus  
#3 Posted : Monday, September 12, 2011 7:05:35 AM(UTC)
Traxus

Rank: Newbie

Groups: Member
Joined: 9/9/2011(UTC)
Posts: 6

Was thanked: 1 time(s) in 1 post(s)
Will the images be stored as a php parse-able array in the HTTP POST?

I am familiar with how to get the information into the database, I'm having difficulty conceptualizing how HTTP POST will make multiple files accessible as opposed to the one at a time fashion that html forms provide.
Dmitry.Obukhov  
#4 Posted : Monday, September 12, 2011 9:33:54 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups:
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello,

You should set filesPerPackage property to 1. In this case, images will be uploaded in the separated POST requests, which you can handle to save images to database. It will be the same as uploading through html form.

If you have any questions please let me know.
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
Traxus  
#5 Posted : Thursday, September 15, 2011 12:36:21 PM(UTC)
Traxus

Rank: Newbie

Groups: Member
Joined: 9/9/2011(UTC)
Posts: 6

Was thanked: 1 time(s) in 1 post(s)
using that method, will the file uploaded callback function (defined via setFileUploadedCallback) execute for each individual file that the uploader sends up, or just when the entirety of the files selected by the user has been uploaded?

in otherwords, would my call back function look like this:

Code:
function onFileUploaded($uploadedFile) {
  //upload individual file to database
}


or more like this?:

Code:
function onFileUploaded($uploadedFile) {
  foreach($uploadedFile as $file) {
    //upload individual file to database
  }
}


**just looking through the documentation some more, it looks like I can do it either way, per the example in this section?

http://www.aurigma.com/d...s-in-php.htm#typedAccess

Edited by user Thursday, September 15, 2011 1:22:26 PM(UTC)  | Reason: Not specified

Dmitry.Obukhov  
#6 Posted : Friday, September 16, 2011 12:08:49 AM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups:
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello,

Please use the first way you show:
Code:
 function onFileUploaded($uploadedFile) {
  //upload individual file to database
}

You can also look through PHP server-side code sample on our basic demo page: just select PHP in the Platform list under Image Uploader control, and open upload.php link.

Edited by user Friday, September 16, 2011 12:09:29 AM(UTC)  | Reason: Not specified

Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
Traxus  
#7 Posted : Monday, September 19, 2011 10:33:51 AM(UTC)
Traxus

Rank: Newbie

Groups: Member
Joined: 9/9/2011(UTC)
Posts: 6

Was thanked: 1 time(s) in 1 post(s)
I got it. Here's how:

Assuming you have setup your mysql table as follows (This tutorial is also a good reference):

Code:

CREATE TABLE `images` (
`image_id` TINYINT( 4 ) NOT NULL AUTO_INCREMENT ,
`image_type` VARCHAR( 25 ) NOT NULL ,
`image_size` VARCHAR( 25 ) NOT NULL ,
`image` MEDIUMBLOB NOT NULL ,
`image_thumb` MEDIUMBLOB NOT NULL ,
`image_title` VARCHAR( 250 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
`image_caption` VARCHAR( 1000 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
PRIMARY KEY (image_id)
) ENGINE = MYISAM 


You can setup your upload.php like this:

Code:

<?php
require_once 'image-uploader/Includes/gallery_helper.php';
require_once 'image-uploader/UploadHandler.class.php';
 
function onFileUploaded($uploadedFile) {

	$username = "user";
	$password = "pass";
	$dbname = "name";

	function injection_proof($x) {
		$x = strip_tags($x);
		$x = htmlspecialchars($x);
		$x = addslashes($x);
		return $x;
	}
	//--title field
	$img_title = $uploadedFile->getSourceName();
	$spaces = array("-", "_");
	$img_title = str_replace($spaces, " ", $img_title);
	$filetypes = array(".jpg", ".png", ".gif", ".tif");
	$img_title = str_replace($filetypes, "", $img_title);
	$img_title = injection_proof($img_title);
	//--caption field
	$img_caption = $uploadedFile->getDescription();
	$img_caption = injection_proof($img_caption);
	//--the image	
	$img = addslashes(file_get_contents($_FILES[sprintf(PostFields::file, 0, $uploadedFile->getIndex())]["tmp_name"]));
	//image type
	$img_meta = getimagesize($_FILES[sprintf(PostFields::file, 0, $uploadedFile->getIndex())]["tmp_name"]);
	
	mysql_connect("localhost", "$username", "$password") OR DIE (mysql_error());
	mysql_select_db ("$dbname") OR DIE ("Unable to select db".mysql_error());
	$sql = "INSERT INTO images( image_id , image_type, image_size, image, image_thumb, image_title, image_caption) VALUES('', '{$img_meta['mime']}', '{$img_meta[3]}', '".$img."', '', '".$img_title."', '".$img_caption."')";	
	// insert the image
	if(!mysql_query($sql)) {
		echo 'Unable to upload file';
	}
}
 
$uh = new UploadHandler();
$uh->setFileUploadedCallback('onFileUploaded');
$uh->processRequest();
?>

Edited by user Monday, September 19, 2011 1:54:20 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Traxus for this useful post.
Dmitry.Obukhov on 9/19/2011(UTC)
Dmitry.Obukhov  
#8 Posted : Monday, September 19, 2011 9:55:46 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups:
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Thank you for your sample. I will put this post to Image Uploader FAQ section on the forum.
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
Users browsing this topic
Similar Topics
Upload images straight to mySQL database? (Discussions – ActiveX/Java Uploader)
by Traxus 9/9/2011 8:54:19 AM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.