php - Putting User Selected Attachments into mysql DB -
i have form customer service reps can insert call logs. want have allows user select file upon form submit uploaded database. can provide example or resource might lead me in right direction?
uploading files using post
i'm assuming want store file on server , not put database (large numbers of files inserted in database blobs incredibly bad performance).
front-end
in short, create upload field in form:
<form enctype="multipart/form-data" action="__url__" method="post"> send file: <input name="call-log" type="file" /> <input type="submit" value="upload log" /> </form>
storing file
then handle upload:
$uploaddir = '/var/www/uploads/'; $uploadfile = $uploaddir . basename($_files['call-log']['name']); if (move_uploaded_file($_files['call-log']['tmp_name'], $uploadfile)) { echo "file valid, , uploaded.\n"; } else { echo "possible file upload attack!\n"; }
remembering location
then put file location in database table (examples using mysqli
(documentation) because mysql
(documentation) attracts nerd-rage):
$filename = basename($_files['call-log']['name']); $mysqli = new mysqli('localhost','some_user','some_password','database'); $stmt = $mysqli->prepare("insert logs (file-location) values (?)"); $stmt->bind_param("s", $filename); $stmt->execute;
examples ad-hoced php documentation.
Comments
Post a Comment