so have searched high , low relevant answer, , have yet find one, i'm going ask question myself. in mysql tables have 5 columns of id, customer__id, file_data, file_name, mime_type
the relevant 1 here file_data
type of longblob
. understand size of files longblob
can handle pretty substantial when try upload file around 978 kb fails, dimensions of image large (2048 x 1536)
?
here code uploader. works elegantly things excel sheets, pdf, word documents, , other stuff, when comes images fails:
<?php require_once '../../inc/config.php'; $response = array(); $response['errors'] = false; $id = $_request['id']; if(!empty($_files)){ //set default data arrays $names = array(); //stores file names $files = array(); //stores file data $mime_types = array(); //store file type mime type //force each file name names array foreach($_files['file']['name'] $name){ array_push($names, $name); } //force file data own array spot in files array foreach($_files['file']['tmp_name'] $temp){ array_push($files, prepareimagedbstring($temp)); } //force mimetypes mime_types array foreach($_files['file']['type'] $type){ array_push($mime_types, $type); } //process 3 of file arrays simultaneously no data left out for($i = 0; $i < count($names); $i++){ $file_name = $names[$i]; $file_data = $files[$i]; $mime_type = $mime_types[$i]; //set query data go note_file table in database $q = "insert brb.files (customer__id, file_name, file_data, mime_type) values('$id', '$file_name', '$file_data', '$mime_type')"; //run query if($stmt = $conn->prepare($q)){ //process errors may occur if(!$stmt->execute()){ printf("error message: %s\n", $conn->error); } } } } echo json_encode($response); function prepareimagedbstring($filepath){ $out = 'null'; $handle = fopen($filepath, 'r'); if($handle){ $content = fread($handle, filesize($filepath)); $content = bin2hex($content); fclose($handle); $out = $content; } return $out; } ?>
if point me in direction fantastic. please not provide answer on why practice bad, i'm aware it's bad practice , know proper practice is, learning tool myself , nothing more, bear me on minute.
thank provides help!