How to upload image in PHP
How to upload image in PHP
Hello, friends today we are going to learn about the submission of forms with files. This is too easy and simple while you are doing coding. so don't be afraid it's simple and easy programmatically I will teach you here each and every step in detail. so your concepts will be clear.while you are working in PHP first you need to start your server so that the code will be run on the server. So I assume that you now the server and know how to start the server and run your code in that.
HTML
<html>
<head>
<title>A simple example of uploading a file using PHP script</title>
</head>
<body>
<b>Simple example of uploading a file</b><br />
Choose a file to be uploaded<br />
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<input type="text" name="ASDF" size="50" />
<br />
<input type="submit" value="Upload" />
</form>
</body>
</html>
PHP
You can upload the file using the PHP in the folder which you gave the path and you also need to save the name of a file in the database table so that you can then use the name again.
if(!empty($_FILES['file'])){?>
$targetfolder = "assets/";
$file_name = $_FILES['file']['name'];
$file_temp = $_FILES['file']['tmp_name'];
echo "<pre>";print_r($_FILES);
if($_FILES['file']['error'] == 0){
move_uploaded_file($file_temp, $targetfolder.$file_name);
echo "The file ". $_FILES['file']['name']. " is uploaded";
}
else {
echo "Problem uploading file";
}
}
Now this is the easiest way to upload the file in custom PHP that is you require the
- file_name
- file_temp
- target folder
Configure Lamp server..!
This Post Was Last Updated On September 30, 2016, By Author: Mahira Khan.
0 comments:
Post a Comment