Pages

file uploading PHP

If you need a upload a file using PHP. This is a easiest and nice way to do that. Only one line I used. You can add validation part according to your need.

Html part

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>


The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data.

The type="file" attribute of the <input> tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field


one line php script

<?php
$path="E:\tharu\";
move_uploaded_file($_FILES["file"]["tmp_name"],$path.$_FILES["file"]["name"]);
?>


[file][tmp_name] - temporary storage of file .now we save this file any place we want
path = specific path
[file][name] - name of the file

No comments:

Post a Comment