As far as I understood the browse button is for client side (web-browser)
Client Side Browse Button
There are 2 parts to it:
- HTML Upload Form
- PHP processing script
HTML [form]
<form enctype="multipart/form-data" action="submit-script.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>
PHP [submit-script.php]
$fileName = $_FILES['uploadedfile']['name'];
$target_path = "uploads/";
$target_path = $target_path . basename($fileName);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " uploaded";
} else{
echo "Unable to upload!";
}
Server Side Browse Button
However if you want to click the browse button and browse the server you will have to implement the browse button yourself with ajax or make the process multi-step.
Ajax-Way
- On button click event open up Modal Window with directory browsing
- There are many open source Directory browsing scripts on the net. Here are few: simple server file browser, fileNice - fancier solution...
- Once you click OK in the modal window, before closing the window set some hidden input on the parent to the selected file (using javascript). E.g. window.parent.selectedFile.value ="selected file"
- Once you save in your main form. Capture the "selectedFile" from POST and do what you need to do.
Non-Ajax Way
You will need multiple forms for this (on different pages). 1st form will have the file browser (see step 2 in Ajax-Way), store selected file to hidden fields. Once passed to 2nd form, set the value to another hidden fields... request additional information (if needed, if not you can skip 2nd form). Once submitted, do what you need to do...