How can you upload a file using PHP

0 votes
I want to upload specific file in my application. How can i do that?

Thank You!
Mar 27, 2020 in PHP by kartik
• 37,520 points
790 views

1 answer to this question.

0 votes

Hello,

To upload a file by using PHP, you have to follow the following steps:

1. Enable file_uploads directive

Open php.ini file and find out the file_uploads directive and make it on.

file_uploads = On

2. Create an HTML form using enctype attribute and file element for uploading the file.

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="upd" id="upd">
<input type="submit" value="Upload" name="upload">
</form>

3. Write PHP script to upload the file

if (move_uploaded_file($_FILES["upd"]["tmp_name"], "Uploads/")) {

echo "The file ". basename( $_FILES["upd"]["name"]). " is uploaded.";

} else {

echo "There is an error in uploading.";

}

Thank You!!

answered Mar 27, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
0 answers
0 votes
1 answer

How can I connect to a Tor hidden service using CURL in PHP?

Hello @kartik, I use Privoxy and cURL to scrape Tor ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,880 points
5,251 views
0 votes
1 answer

How can I upload Multiple file in php?

Hello @kartik, Multiple files can be selected and ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,880 points
768 views
0 votes
1 answer

How to copy a file from one directory to another using PHP?

Hello @kartik, You could use the copy() function : // Will ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,880 points
1,336 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,626 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
1,376 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
957 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,880 points
2,333 views
0 votes
1 answer

How do you create a .gz file using PHP?

Hello @kartik, This code does the trick // Name ...READ MORE

answered Nov 6, 2020 in PHP by Niroj
• 82,880 points
2,698 views
0 votes
1 answer

How can one check to see if a remote file exists using PHP?

Hello @kartik, You can instruct curl to use ...READ MORE

answered Nov 10, 2020 in PHP by Niroj
• 82,880 points
1,180 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP