1

Some weeks ago I had this html/php code to upload for instance a .txt file to a specific folder in my wwwroot directory on my host server, it all worked as desired.

As my subscription which I had for the host server, ran out. I was forced to temporarily copied all my html/php files to my xampp (htdocs) folder. Now when I try to upload a specific folder via localhost/ it gives me the following message:

Upload failed

Here is some more debugging info:Array

(
    [uploaded_file] => Array
        (
            [name] => FREESTYLE.txt
            [type] => text/plain
            [tmp_name] => /Applications/XAMPP/xamppfiles/temp/php5Bg8XM
            [error] => 0
            [size] => 34
        )

)

I have no idea what is going on, perhaps a xampp config file that doesn't let me upload files to any folder in xampp?

the code I use for uploading files is respectfully as follows:

HTML:

<!DOCTYPE html>
<html>
<head>

<style type="text/css">
body{
    background-image: url("images/bg.jpg");
    background-color: #844903;
    }
    .logo{
    position: absolute;
    top: 40px;
    right: 850px;
    }
    h1{
    position: absolute;
    top: 200px;
    right: 820px;
    color: #a86b00;
    }  
    </style>

 <title></title>
</head>
<body>

     <div class="logo"><img src="images/logo.jpg" alt="logo"></div>

    <h1>Please Upload Your Notes:</h1>

   <form enctype="multipart/form-data" action="upload.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>
</body>
</html>

PHP:

<?php

$uploaddir = '/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo "<p>";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Upload failed";
}

echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";

?> 

Anyone an idea what's going on?

Thank you for you time.

-M

4
  • Check your permissions on the uploads directory. You probably don't have the appropriate write access to it. Commented Apr 29, 2015 at 17:50
  • jup, tried that one already. Just for the heck of it, I put everything between 775 and 777 permission-wise. Commented Apr 29, 2015 at 17:51
  • [error] => 0 means no error. just the set the appropriate permissions on the destination folder. i.e.: chmod 777 /path/to/upload/folder/ Commented Apr 29, 2015 at 17:57
  • I tried this, but to no avail. Commented Apr 29, 2015 at 18:22

1 Answer 1

3

I Solved the Problem. Instead of '/uploads/' ---> 'uploads/' because it is already in the htdocs folder. So that's why it doesn't need the first forward slash.

Thank you all for putting time into my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.