Move uploaded file function is not working

0 votes

I have been working on a website and I want the user to be able to upload files which is why I'm trying to learn how to do that. I have researched it and it said that I had to use the function move_uploaded_file(). I wrote the code just like it was on the example, but it wouldn't work. Please help me, I'm new at these. Here's what I've done so far:

<!DOCTYPE html> 
<html> 
          <head> 
          </head> 
<body> 
        <form action="upload_file.php" method="POST" enctype="multipart/form-data"> 
            <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> 
            <input type="file"name="file"> 
            <input type="submit"> 
      </form> 
</body> 
<html>


This is the upload_file.php:

<!DOCTYPE html> 
<html> 
    <head> 
      <head> 
          <body> 
            <?php 
              $move = "/Users/George/Desktop/uploads/"; 
                echo $_FILES["file"]['name']."<br>"; 
                echo $_FILES["file"]['tmp_name']."<br>"; 
                echo $_FILES["file"]['size']."<br>"; 
                echo $_FILES['file']['error']."<br>"; move_uploaded_file($_FILES['file']['name'], $move);      ?> 
<body> 
<html>
Feb 22 in Others by Rahul
• 8,980 points
67 views

1 answer to this question.

0 votes

The file will be stored in a temporary location, so use tmp_name instead of name:

if (move_uploaded_file($_FILES['image']['tmp_name'], __DIR__.'/../../uploads/'. $_FILES["image"]['name'])) { 
      echo "Uploaded"; } 
else { 
    echo "File not uploaded"; 
}

answered Feb 22 by Aditya
• 7,280 points

Related Questions In Others

+1 vote
0 answers
0 votes
1 answer

why aws s3 transfer acceleration is not working?

Essentially, rather than travelling the Internet to ...READ MORE

answered Mar 24 in Others by gaurav
• 13,560 points
103 views
0 votes
1 answer

why aws s3 transfer acceleration is not working?

Amazon S3 Transfer Acceleration is a bucket-level ...READ MORE

answered Mar 24 in Others by gaurav
• 13,560 points
63 views
0 votes
0 answers

How to use Unlink() function

I tried using the PHP unlink() function to ...READ MORE

Jun 13 in PHP by narikkadan
• 10,840 points
7 views
0 votes
0 answers

How to write into a file in PHP?

I have this script on one free ...READ MORE

Jun 20 in PHP by Kithuzzz
• 320 points
5 views
0 votes
0 answers

Read a plain text file with php

How do I read all the information ...READ MORE

Jun 26 in PHP by narikkadan
• 10,840 points
15 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
526 views
0 votes
1 answer

TypeError: $.ajax(...) is not a function?

Please double-check if you're using the full-version ...READ MORE

answered Feb 22 in Others by Aditya
• 7,280 points
195 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP