MSD
MSD

Reputation: 313

XAMPP php file upload to folder fails

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

Upvotes: 1

Views: 13289

Answers (1)

MSD
MSD

Reputation: 313

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.

Upvotes: 3

Related Questions