I am uploading files to a database, although i was told that it is faster to upload gif's and jpg's to a directory on the server. I am having problems uploading the files to the database.
I am using a file for field and a max image size field on the html form and am uploading 2 images at one time, using php 4.2.2. When I run the script I am able to do database inserts, but the images don't upload. I am only using a file text box on the form, should I be using more on the form?
Here is my php code to check the image type.
<PHP>
function picture1($type, $picture1, $ext, $connection)
{
//get info about the image being uploaded
list($type, $ext) = getimagesize($picture1);
switch ($type)
{
case 1:
$ext = ".gif";
break;
case 2:
$ext = ".jpg";
break;
case 3:
$ext = ".swf";
break;
default:
echo "Sorry, but the file you uploaded was not a GIF, JPG, or SWF file.<br>";echo "Please hit your browser's 'back' button and try again.";
}
}
</PHP>
Here is how I do my validation and how I use the $_POST array. I am not validating the images here.
<PHP>
// Clean and trim the POSTed values MAY not need this or may have to do this another way
foreach($_POST as $varname => $value)
$pageFormVars[$varname] = clean($value, 512);
// Validate the home, about, and native anmerican categories apges
if (($id == 1) || ($id == 3) || ($id >= 5) && ($id <= $cat))
{
// Validate pgtitle
if (empty($pageFormVars["pgtitle"]))
// The pgtitle for the home page cannot be NULL
$errorString .= "\n<br>The pgtitle field cannot be blank.";
// Validate pgdesc
if (empty($pageFormVars["pgdesc"]))
// The pgdesc for the home page cannot be NULL
$errorString .= "\n<br>The pgdesc field cannot be blank.";
</PHP>
Here is how I do my picture upload.
<PHP>
// update picture 1
if (is_uploaded_file($FILES["picture1"]["pic1"]))
{
picture1($type, $picture1, $ext, $connection);
if (!($result = @ mysql_query ("UPDATE picture set
picture1 = '{$FILE["pageFormVars"]["picture1"]}'
WHERE picid = {$pageid}", $connection)))
showerror();
}
</PHP>