Jump to content


Photo

Submitting BLOB to SQL database


  • Please log in to reply
2 replies to this topic

#1 eyehawk78

eyehawk78
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 April 2006 - 10:07 PM

I am trying to use a html upload field to allow users to submit images to me that will be placed in my sql data base.
i have sorted out the vaildation and submits the name and size to the database, but i need help with actually submitting the image to the database as a BLOB

so the code i have is:

<HTML>
<HEAD>

<?php

$error = "";
$valid=0;

$filename = $HTTP_POST_FILES['file']['name'];
$filesize = $HTTP_POST_FILES['file']['size'];
$filetype = $HTTP_POST_FILES['file']['type'];
$filetempname = $HTTP_POST_FILES['file']['tmp_name'];


if(!$filename == ""){
if($filetype == "image/gif"){
$error = "successful";
$valid++;
}
else if($filetype == "image/x-png"){
$error = "successful";
$valid++;
}
else if($filetype == "image/pjpeg"){
$error = "successful";
$valid++;
}
else if($filetype == "image/bmp"){
$error = "successful";
$valid++;
}
else {
$error = "Incorrect file type, please upload image files of type .gif .bmp .png or .jpeg";
$valid=0;
}
$maxsize=65536;
$minsize=1024;
if($error == "successful"){
if($filesize <= $minsize){
$error = "The file is too small, when this logo is placed onto shirt it will be disorted";
$valid=0;
}
else if($filesize > $maxsize){
$error = "The file is too large";
$valid=0;
}
else {
$error = "The file was successfully uploaded";
$valid++;
}
}

if($valid==2){

$dbUser="blahblah";
$dbHost="blahblah";
$dbName="blahblah";
$dbPass="blahblah";

$dbc=mysql_connect($dbHost,$dbUser,$dbPass);
$selected=mysql_select_db($dbName,$dbc);

$query1="INSERT INTO upload VALUES('', '$filename', '$filetype', '$filesize', [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'this is were the blob field is in my database[!--colorc--][/span][!--/colorc--]')";
if(mysql_query($query1)){
$error == "Your file was successfully submitted";
}
else {
$error == "Your file could not be submitted";
}
$valid=0;
}
$filename = "";
$filesize = "";
$filetype = "";
$filetempname = "";
}
?>

</HEAD>
<BODY>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<font face="Verdana" color="#000000" font size="2" >Choose a file to upload:<br></font>
<input type="file" name="file">
<input type="submit" name="submit" value="Submit">
<br><br>
<font face="Verdana" color="#000000" font size="2" ><?php print("$error</br>"); ?></font>
</form>
</BODY>
</HTML>

could any one help me please?

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 12 April 2006 - 08:49 AM

Sorry i'm unable to post the answer as it wont update the post! very weird! heres a link to what the correct code should be :)

[a href=\"http://pctechsupport.sytes.net/blobdatabase.phps\" target=\"_blank\"]http://pctechsupport.sytes.net/blobdatabase.phps[/a]

Ther's your answer
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 eyehawk78

eyehawk78
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 19 April 2006 - 09:37 PM

Hi sorry to bother you again but i ran your code and i recieved to warnings.

Warning: fread(): supplied argument is not a valid stream resource in C:\unzipped\CPT 06\uploadpage.php on line 14

Warning: fclose(): supplied argument is not a valid stream resource in C:\unzipped\CPT 06\uploadpage.php on line 16

what do these warnings mean?

The blob size is still 0 bytes in my database.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users