The Codesee The Codesee - 1 year ago 100
HTML Question

Upload image immediately after selected

My goal is to automatically upload an image to a folder when the file is selected. Following the answer on how do I auto-submit an upload form when a file is selected, I attempted to use Javascript's

event to automatically submit the form:

$ImageName = $_FILES['photo']['name'];
$fileElementName = 'photo';
$path = '../images/';
$location = $path . $_FILES['photo']['name'];
move_uploaded_file($_FILES['photo']['tmp_name'], $location);

<form method="post" enctype="multipart/form-data">
<input type="file" name="photo" onchange="document.getElementById('upload').submit();" id="file" class="inputfile" />
<label for="file">Add Image</label>
<input type="submit" style="display: none;" name="upload" id="upload">
<input type="text">
<input type="submit">

When the file is selected, it's not automatically uploaded to a folder.

Note: I cannot use
as I have multiple submit buttons in my form!

Answer Source

I think you could simply change it to:


Or do something like this:

var button = document.getElementById('upload');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download