0

So I built this simple script to upload files to an XAMPP server, and . . . it didn't work. When I ran it, it dies after the first if statement. EDIT: FIXED

Here's the FIXED html code:

<!DOCTYPE html>

<html>
<head>
<title>Awesome Life: File Upload</title>
<link rel="stylesheet" href="forms.css">
</head>
<body>
<div id="big_wrap">
    <section id="sign_up">
        <form action="http://localhost/mail.php" method="post" ENCTYPE="multipart/form-data">
            <span id="upText">File to Upload</span> 
            <br />
            <input style="margin-top:5px;" type="file" name="fileName">
            <br />
            <br />
            <input type="submit" id="button" name="submit" value="Upload">
        </form>
    </section>
</div>
</body>
</html>

And here's the FIXED script:

<?php
if(!isset($_FILES["fileName"])){
    die("It didn't work!");
}else{
    move_uploaded_file($_FILES["fileName"]["tmp_name"], "\xampp\htdocs\".$_FILES["fileName"]  ["name"]) or die("Didn't work");
}
?>

The file type isn't determined or tested, as I'm not going to be using this on the World Wide Web. I'm simply wondering why it doesn't work. Thanks!

EDIT: It was a simple matter of changing the edit permissions of the htdocs folder. I unchecked the read-only box and it worked fine. Thanks to all for contributing, and especially to Fred -ii-

7
  • We're gonna need to know more than just "It doesn't work tell me why". What is in your php.ini files regarding file uploads? How big is the file you're uploading and what MIME type does it have? (There is a default MB upload value that you may have to adjust) Commented Feb 27, 2014 at 16:18
  • These are the rules specified in the php.ini: file_uploads=On, upload_tmp_dir=C:\xampp\tmp, upload_max_filesize=2M, max_file_uploads=20, Commented Feb 27, 2014 at 16:20
  • Read the manual and make sure folders have write permissions. @crazyjedi98 and you probably need another \ in "\xampp\htdocs" as "\xampp\htdocs\" or may need to do "/xampp/htdocs/" Commented Feb 27, 2014 at 16:26
  • Fred -ii-, you are beast. All I had to do was remove the "read-only" permission from the htdocs folder and add another slash to the end. The other answers helped a lot, too. Commented Feb 27, 2014 at 16:36
  • Aahhhh good, nice to hear it's solved!! :) Commented Feb 27, 2014 at 16:37

3 Answers 3

2

multipart/file-data is incorrect. It should be multipart/form-data instead.

Also, you should use move_uploaded_file to move the uploaded file somewhere. Not copy.

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

2 Comments

Changed the file-data to form-data and there's no difference. Also used the move_uploaded_file() and it didn't work, either. All I'm uploading for practice is a small .jpg file, 3.67 KB.
HEY FOLKS IT WAS FRED -ii- THAT SOLVED A BIG HALF OF MA PROBLEM AS WELL! CHECK OUT HIS COMMENTS ON THE QUESTION!!!!
2

replace form attribute

ENCTYPE="multipart/file-data"

to

ENCTYPE="multipart/form-data"

Comments

0

Turns out it was a mix of many things, but as OP stated: (and more importantly)

"Fred -ii-, you are beast. All I had to do was remove the "read-only" permission from the htdocs folder and add another slash to the end. The other answers helped a lot, too"

Answer transformed from my comment:

(Main problem) Make sure folders have write permissions. and you probably need another \ in "\xampp\htdocs" as "\xampp\htdocs\" or may need to do "/xampp/htdocs/"

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.