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
|
1 user thanked Traxus for this useful post.
|
|