Jump to content

Uploading images to SQL


eyehawk78

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?
Link to comment
https://forums.phpfreaks.com/topic/7146-uploading-images-to-sql/
Share on other sites

Archived

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

×
×
  • Create New...

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.