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 8540845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:41:36+00:00 2026-06-11T11:41:36+00:00

I can’t seem to get files to be uploaded with PHP. From what I

  • 0

I can’t seem to get files to be uploaded with PHP. From what I can tell, everything checks out. I even went as far as digging up the old textbook and copied the example straight out of the text and still no go.

At first, I was thinking it was an issue with the directory permissions where the files are being saved so I changed permissions to 777 and still nothing. If anyone has any suggestions I’m all ears :/

Here is the code (HTML):

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

The PHP file:

<?php
$tmp_name = $_FILES['file1']['tmp_name'];
$path = getcwd() . DIRECTORY_SEPARATOR . 'images';
$name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name'];
$success = move_uploaded_file($tmp_name, $name);
if($success) {
    $upload_message = $name . ' has been uploaded.';
    echo "$upload_message";
} else {
    echo "something went wrong :(";
}
?>
  • 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-11T11:41:37+00:00Added an answer on June 11, 2026 at 11:41 am

    You should be checking for an upload error before attempting to move it then you can track down the problem:
    http://www.php.net/manual/en/features.file-upload.errors.php

    Heres a basic example:

    <?php
    error_reporting(-1);
    
    $uploaddir = './images/';
    
    // Check for upload attempt
    if(isset($_FILES['file1'])){
        $uploadfile = $uploaddir.basename($_FILES['file1']['name']);
    
        // If no error
        if($_FILES['file1']['error'] == 0){
            //Attempt to move
            if (move_uploaded_file($_FILES['file1']['tmp_name'], $uploadfile)) {
                echo "File is valid, and was successfully uploaded.";
            }else{
                echo 'Error moving file.';
            }
        } else {
            // Has error
            $errors = array(0=>'OK',
                            1=>'UPLOAD_ERR_INI_SIZE',
                            2=>'UPLOAD_ERR_FORM_SIZE',
                            3=>'UPLOAD_ERR_PARTIAL',
                            6=>'UPLOAD_ERR_NO_TMP_DIR',
                            7=>'UPLOAD_ERR_CANT_WRITE',
                            8=>'UPLOAD_ERR_EXTENSION'
                            );
            echo "Error: ".$errors[$_FILES['file1']['error']];
        }
    }
    

    BTW. Be very wary of allowing uploads.

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

Sidebar

Related Questions

Can any one tell, how to get the result of LINQ query contains group
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can anyone tell me how to get the update datatime for profile picture of
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can't figure out how to do this in a pretty way : I have
Can someone tell me how does the imdb app manage to play trailers on
Can any one tell me clearly why ? Reading is simple in ArrayList,( we
Can I prevent an .apk from being installed if unknown sources is checked?

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.