mysql - PHP - file not sending to database error -
i allow users submit files database on website. every time file submitted, these error messages
( ! ) warning: file_get_contents() expects parameter 1 valid path, array given in c:\wamp64\www\mt\developerupload.php on line 8 ( ! ) warning: trim() expects parameter 1 string, array given in c:\wamp64\www\mt\developerupload.php on line 9
but told "file_get_contents" way send file contents database. without "file_get_contents" sends it, gives me error messages , not sure why. want is, submit file using "file_get_contents" later on can display content on users page. here code
php
$query = "insert pack_screenshots(pack_id, file_name, file_tmp)values(:packid, :file_name, :file_tmp)"; $stmtfileupload = $handler->prepare($query); $errors = array();
foreach($_files['file']['tmp_name'] $key => $error){ if ($error != upload_err_ok) { $errors[] = $_files['file']['name'][$key] . ' not uploaded.'; continue; } $file_tmp = file_get_contents($_files['file']['tmp_name']); $file_name = addslashes(trim($_files['file']['name'])); try{ $stmtfileupload->bindparam(':packid', $packid, pdo::param_str); $stmtfileupload->bindparam(':file_name', $file_name, pdo::param_str); $stmtfileupload->bindparam(':file_tmp', $file_tmp, pdo::param_str); $stmtfileupload->execute(); $dir = "devfiles"; if(is_dir($dir)==false){ mkdir($dir, 0700); } if(is_file($dir.'/'.$file_name)==false){ move_uploaded_file($file_tmp,$dir.'/'.$file_name); }else{ $_session['invalid'] = true; header("location: developer_invalid.php"); exit; } $_session['thankyou'] = true; header("location: developerupload_thankyou.php"); exit; }catch(pdoexception $e){ $errors[] = $file_name . 'not saved in db.'; echo $e->getmessage(); } }
your problem have no keys associated 2 lines giving error (and elsewhere in code), therefore arrays (as not selecting specific key).
you need associate keys $_files array.
$file_tmp = file_get_contents($_files['file']['tmp_name'][$key]); $file_name = addslashes(trim($_files['file']['name'][$key]));
Comments
Post a Comment