learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
I thought this was going to be easy....
I have a file upload input and then use..
which I thought would prepare it fine..
Now my sanitise function is
Which can handle a variety of values dependent on content type.
The insert MYSQL is
This seems to work fine, but when I try to upload a larger image (<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">, it seems to store fine but only displays the upper half of the image when downloading.
I get loads of problems with other file types - docs get corrupted - pdf's don't download successfully - bit of a nightmare!
So I thought - am I not preparing correctly?
The first move was...
With the result...
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0<\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0' at line 1
So I tried
And got
Unknown column '$fileContent' in 'field list'
Arrrgghhh - what am I doing wrong?
I have a file upload input and then use..
PHP:
$fileHandle = fopen($fileUpload, "r");
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
which I thought would prepare it fine..
Now my sanitise function is
PHP:
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
Which can handle a variety of values dependent on content type.
The insert MYSQL is
PHP:
$insertSQL = sprintf("INSERT INTO FILEATT (ATTNOTEID, CREATEDATE, CREATEDBY, SUBJECT, ATTACHMENT, LONGNOTE, FILENAME, FILE, FILETYPE) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString( $_POST['hiddenfieldnotesid'], "int"),
GetSQLValueString( $_POST['hiddenfieldcreated'], "date"),
GetSQLValueString( $_POST['hiddenfieldcreatedby'], "text"),
GetSQLValueString( $_POST['textfieldtitle'], "text"),
GetSQLValueString($_POST['path'], "text"),
GetSQLValueString($_POST['longnote'], "text"),
GetSQLValueString($fileUpload_name, "text"),
GetSQLValueString($fileContent, "text"),
GetSQLValueString($fileUpload_type, "text")
);
This seems to work fine, but when I try to upload a larger image (<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">, it seems to store fine but only displays the upper half of the image when downloading.
I get loads of problems with other file types - docs get corrupted - pdf's don't download successfully - bit of a nightmare!
So I thought - am I not preparing correctly?
The first move was...
PHP:
$insertSQL = sprintf("INSERT INTO FILEATT (ATTNOTEID, CREATEDATE, CREATEDBY, SUBJECT, ATTACHMENT, LONGNOTE, FILENAME, FILE, FILETYPE) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString( $_POST['hiddenfieldnotesid'], "int"),
GetSQLValueString( $_POST['hiddenfieldcreated'], "date"),
GetSQLValueString( $_POST['hiddenfieldcreatedby'], "text"),
GetSQLValueString( $_POST['textfieldtitle'], "text"),
GetSQLValueString($_POST['path'], "text"),
GetSQLValueString($_POST['longnote'], "text"),
GetSQLValueString($fileUpload_name, "text"),
$fileContent,//direct entry with addslashes value
GetSQLValueString($fileUpload_type, "text")
);
With the result...
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0<\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0' at line 1
So I tried
PHP:
$insertSQL = sprintf("INSERT INTO FILEATT (ATTNOTEID, CREATEDATE, CREATEDBY, SUBJECT, ATTACHMENT, LONGNOTE, FILENAME, FILE, FILETYPE) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString( $_POST['hiddenfieldnotesid'], "int"),
GetSQLValueString( $_POST['hiddenfieldcreated'], "date"),
GetSQLValueString( $_POST['hiddenfieldcreatedby'], "text"),
GetSQLValueString( $_POST['textfieldtitle'], "text"),
GetSQLValueString($_POST['path'], "text"),
GetSQLValueString($_POST['longnote'], "text"),
GetSQLValueString($fileUpload_name, "text"),
'$fileContent',//direct entry with addslashes value
GetSQLValueString($fileUpload_type, "text")
);
And got
Unknown column '$fileContent' in 'field list'
Arrrgghhh - what am I doing wrong?