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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -