Skip to content
Snippets Groups Projects
Commit aa2bc152 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add check for file upload error and ability to bailout of a failed chunked INSERT

parent 5a161de3
No related branches found
No related tags found
No related merge requests found
...@@ -141,7 +141,7 @@ class AttachmentFile { ...@@ -141,7 +141,7 @@ class AttachmentFile {
/* Function assumes the files types have been validated */ /* Function assumes the files types have been validated */
function upload($file) { function upload($file) {
if(!$file['name'] || !is_uploaded_file($file['tmp_name'])) if(!$file['name'] || $file['error'] || !is_uploaded_file($file['tmp_name']))
return false; return false;
$info=array('type'=>$file['type'], $info=array('type'=>$file['type'],
...@@ -160,13 +160,6 @@ class AttachmentFile { ...@@ -160,13 +160,6 @@ class AttachmentFile {
$file['hash']=MD5(MD5($file['data']).time()); $file['hash']=MD5(MD5($file['data']).time());
if(!$file['size']) if(!$file['size'])
$file['size']=strlen($file['data']); $file['size']=strlen($file['data']);
//TODO: Do chunked INSERTs -
if(($mps=db_get_variable('max_allowed_packet')) && $file['size']>($mps*0.7)) {
@db_set_variable('max_allowed_packet',$file['size']+$mps);
}
$sql='INSERT INTO '.FILE_TABLE.' SET created=NOW() ' $sql='INSERT INTO '.FILE_TABLE.' SET created=NOW() '
.',type='.db_input($file['type']) .',type='.db_input($file['type'])
...@@ -178,11 +171,15 @@ class AttachmentFile { ...@@ -178,11 +171,15 @@ class AttachmentFile {
return false; return false;
foreach (str_split($file['data'], 1024*100) as $chunk) { foreach (str_split($file['data'], 1024*100) as $chunk) {
if (!db_query('UPDATE '.FILE_TABLE.' SET filedata = CONCAT(filedata,' $sql='UPDATE '.FILE_TABLE
.db_input($chunk).') WHERE id='.db_input($id))) .' SET filedata = CONCAT(filedata,'.db_input($chunk).')'
# Remove partially uploaded file contents .' WHERE id='.db_input($id);
if(!db_query($sql)) {
db_query('DELETE FROM '.FILE_TABLE.' WHERE id='.db_input($id).' LIMIT 1');
return false; return false;
}
} }
return $id; return $id;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment