1

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"

Hkachhia
  • 4,463
  • 6
  • 41
  • 76
Kelvin Bala
  • 97
  • 2
  • 2
  • 11

2 Answers2

1

You need to redirect the user with

 header("Location: yourpage.php");

Also, submitting your form that way might not work on every browser.

Jean-Georges
  • 658
  • 4
  • 12
  • thanks very much, i have tried using this method but i failed in the past, seen that i have no other option – Kelvin Bala Jan 28 '13 at 22:34
  • i have a session variable called **$_SESSION['UserTO']** i would like to take along this session variable for example header('Location: http://localhost/chat1/chat.php'$usernameto=$_SESSION['UserTO'];); but it gives me some errors, is this correct? – Kelvin Bala Jan 28 '13 at 22:35
0
<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

Community
  • 1
  • 1
e-Learner
  • 517
  • 1
  • 4
  • 15