Jump to content

Archived

This topic is now archived and is closed to further replies.

eyehawk78

Submitting BLOB to SQL database

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.