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
• 9,680 points
660 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,660 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 in Others by narikkadan
• 37,660 points
26 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 in Others by gaurav
• 22,040 points
405 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
• 22,040 points
207 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
• 37,660 points
32 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
• 20,660 points
37 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
• 37,660 points
58 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
613 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,660 points
1,537 views
0 votes
1 answer
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