Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:48:40+00:00 2026-06-06T07:48:40+00:00

So I am trying to do a basic upload via an HTML form and

  • 0

So I am trying to do a basic upload via an HTML form and a simple php script, but the move_uploaded_file function always returns false. I have run "chmod 777" on the directory (I will deal with safety more when I actually get this to work) and the "upload" directory is in the htdocs folder (actually /var/www in Ubuntu Server and Linux Mint).

Here is the form:

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

…and upload_file.php…

<?php
    if ($_FILES["file"]["error"] == 0){
        if (file_exists("upload/" . $_FILES["file"]["name"])){
            echo $_FILES["file"]["name"] . " already exists. ";
        }else{
            if(move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/upload/" . $_FILES["file"]["name"])){ 
                echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
            }else{
                echo "Failed to move uploaded file";
            }
        }
    }else{
        echo "Return Code: " . $_FILES["file"]["error"];
    }
?>

When I try to upload a small JPEG, I get "Failed to move file". Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:48:42+00:00Added an answer on June 6, 2026 at 7:48 am

    Your script needs to be able to write to the destination directory, which in this case would be /var/www/upload/ (is that the directory where you changed the permissions?). Also you are using the client’s local name which could be a possible problem and security issue (not necessarily the reason here though).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to my server using php script to upload some files...
I'm trying to add a file upload script in php to a website I'm
I initialize the variables, use move_uploaded_file function and then I write a basic form
I am trying to do a plain multipart form upload using System.Net.WebClient and Basic
I am trying to style a basic HTML form that uses an image background:
I am trying to load a very basic XML document but everytime I get
I'm trying to understand the basic MVVM design approach, but I dont' understand where
I am new to php. Trying to send confirmation about user upload. I am
Having submitted a form with a file to upload, I'm having trouble trying to
So I am trying to execute some script from my php code. That lives

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.