File uploading using php is very simple, follow this step by step tutorial to upload file
Make a Form First
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file">
<input type="submit" name="submit">
</form>
Check if Form Submitted
if(isset($_POST['submit'])){
Set folder path as below you can set your folder path simple make changes after global variable
"$_SERVER['DOCUMENT_ROOT']"
.like suppose your folder name is upload and it is exist on project root directory then you can write path like this $_SERVER['DOCUMENT_ROOT'].'/upload/';
my folder path as below
$target_dir = $_SERVER['DOCUMENT_ROOT'].'/admin/documents/';
get file name
$target_file = $target_dir . basename($filename);
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $target_file)) {
echo "The file ". basename( $_FILES["upload_file"]["name"]). " uploading done.";
} else {
echo "Sorry, there was an error occur uploading your file.";
}
}
No comments:
Post a Comment