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, 2022 in Others by Rahul
• 9,670 points
2,685 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, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
1 answer

Excel MATCH function is not working on an array but works once directed to the matched value

According to the definition here: support.microsoft.com/en-us/office/… if you do ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,420 points
661 views
0 votes
1 answer

Excel SUM function is not working (shows 0), but using Addition (+) works

The values in A1 and A2 are ...READ MORE

answered Jan 5, 2023 in Others by narikkadan
• 63,420 points
360 views
+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, 2022 in Others by gaurav
• 23,260 points
1,027 views
0 votes
0 answers

How to use Unlink() function

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

Jun 13, 2022 in PHP by narikkadan
• 63,420 points
253 views
0 votes
0 answers

How to write into a file in PHP?

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

Jun 20, 2022 in PHP by Kithuzzz
• 38,010 points
191 views
0 votes
0 answers

Read a plain text file with php

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

Jun 26, 2022 in PHP by narikkadan
• 63,420 points
417 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
1,187 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, 2022 in Others by Aditya
• 7,680 points
5,030 views
0 votes
1 answer

'adb' is not recognized as an internal or external command, operable program or batch file

Set the path of adb into System ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
6,310 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