Current location: Hot Scripts Forums » Programming Languages » PHP » image in db


image in db

Reply
  #1 (permalink)  
Old 03-03-08, 02:46 PM
techker techker is offline
Newbie Coder
 
Join Date: May 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
image in db

hey guys i found a tutorial but the script does not seem to work and i can't figure it out?

it gives me on top og the page this
0){ echo "Image has been inserted succesfully"; } else { echo "Image can not be inserted check your submission"; } } else { echo "This is not a true image type"; } } ?>

like if there is missing a { or; somewere?

PHP Code:

<?

mysql_connect
("localhost""root""") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());

  
/*
    This function take the image from form variables
                            */

function getImageFile($file){
$takeFile fopen($file"r");
$file fread($takeFilefilesize($file));
fclose($takeFile);

return 
$file;
}

  
/*
    We learn image type using this function
    Because we will let onlt gif, jpg and png images can be uploaded
                            */

function getfileType$name ){
$name explode("."$name);
$name array_reverse($name);
$name $name[0];
return 
$name;
}

$allowedImageTypes = array("gif","jpg","png");
if(empty(
$_FILES['image_file']['tmp_name'])){
echo 
"File not uploaded";
}
else {
$fileType $_FILES['image_file']['name'];

if(
in_array(getfileType($fileType), $allowedImageTypes)){
$fileContent getImageFile($_FILES['imgFile']['tmp_name']);

$uploadedImage chunk_split(base64_encode($fileContent));

$query "INSERT INTO images_table VALUES('NULL','$imgName','$uploadedImage')";

$result mysql_query($query);

if(
mysql_affected_rows() > 0){

echo 
"Image has been inserted succesfully";
}
else {
echo 
"Image can not be inserted check your submission";
}
}
else {
echo 
"This is not a true image type";
}
}
?>
Reply With Quote
  #2 (permalink)  
Old 03-03-08, 02:53 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Replace <? with <?php. Seems like your server has short tags disabled.
Reply With Quote
  #3 (permalink)  
Old 03-03-08, 02:59 PM
techker techker is offline
Newbie Coder
 
Join Date: May 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
yap it's that but the script does not work..lol
Reply With Quote
  #4 (permalink)  
Old 03-03-08, 03:04 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Do you get any errors? Did you create the database table?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A script to scrape a current image and store it in a db, always using the same name? wolfdogg Script Requests 1 12-08-06 01:10 AM
Pull image path from db and display Rollo Tamasi PHP 1 06-12-06 06:24 PM
Image from DB Omega2 Windows .NET Programming 3 09-29-04 06:13 PM
how to draw an image inside a table? davidklonski HTML/XHTML/XML 2 07-06-04 10:27 AM
upload script which copys image name in db marky7890 PHP 1 05-18-04 05:17 PM


All times are GMT -5. The time now is 07:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.