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 {
/* Function assumes the files types have been validated */
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;
$info=array('type'=>$file['type'],
......@@ -160,13 +160,6 @@ class AttachmentFile {
$file['hash']=MD5(MD5($file['data']).time());
if(!$file['size'])
$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() '
.',type='.db_input($file['type'])
......@@ -178,11 +171,15 @@ class AttachmentFile {
return false;
foreach (str_split($file['data'], 1024*100) as $chunk) {
if (!db_query('UPDATE '.FILE_TABLE.' SET filedata = CONCAT(filedata,'
.db_input($chunk).') WHERE id='.db_input($id)))
# Remove partially uploaded file contents
$sql='UPDATE '.FILE_TABLE
.' SET filedata = CONCAT(filedata,'.db_input($chunk).')'
.' 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 $id;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment