Attach file in php and inserting in a database
this is a normal html method of attaching a file.
form enctype=<"multipart/form-data" action="savefile.php" method="POST" name="myform">
Send this file: input name="myfile" type="file" onchange="document.forms['myform'].submit() ;"
/form>
savefile.php
move_uploaded_file($_FILES["myfile"]["tmp_name"],
"upload/" . $_FILES["myfile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["myfile"]["name"];
it works perfectly, my difficulty is that when i attach a file and it sends, when i refresh the page, the file i attached still remains in the attachment, how can i clear it so it shows "No chosen file" thnks
You need to redirect the user with
header("Location: yourpage.php");
Also, submitting your form that way might not work on every browser.
<input name="myfile" type="file" onchange="document.forms['myform'].submit() ;" />
And JAVASCRIPT
var myInput = $("#input[name='myfile']");
function resetInput(){
myInput.replaceWith( myInput.val('').clone( true ) );
};
Call resetInput()
after the upload.
Ripped and adapted From this thread
链接地址: http://www.djcxy.com/p/64858.html上一篇: 使用数字键作为对象来投射数组
下一篇: 在php中附加文件并插入数据库