Dan Hacky
Dan Hacky

Reputation: 3

uploading file to folder on website via PHP

I would like to have the user upload a pdf to a folder on my website. (note:this is for learning purposes, so security is not necessary) The code I have below does not do echo a response when submitted. The folder I would like to have the pdf uploaded to is in the same directory as the php script, is it possible I'm incorrectly referencing that folder? I appreciate it.

<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
Email:<br /> <input type = "text" name="email" value=""/><br />
Resume:<br /><input type = "file" name="resume" value=""/><br />
<p><input type="submit" name ="submit" value="Submit Resume" /></p>
</form>


if(isset($_POST['submit']))
{
    define ("FILEREPOSITORY","./resume/");

    if (is_uploaded_file($_FILES['resume']['tmp_name'])) {
        if ($_FILES['resume']['type'] != "application/pdf") {
            echo "<p>Resume must be in PDF Format.</p>";
        }
    }else {
        $name = $_POST['email'];

        $result = move_uploaded_file($_FILES['resume']['tmp_name'], FILEREPOSITORY."/$name.pdf");

        if ($result == 1) {
            echo "<p>File successfully uploaded.</p>";
        }
        else {
            echo "<p>There was a problem uploading the file.</p>";
        }

    }

}

Upvotes: 0

Views: 1464

Answers (3)

macjohn
macjohn

Reputation: 1803

IT would be of great help to give the error you receive.

move_uploaded_file()

only works if you have the rights to write to the destination folder.

Upvotes: 0

optimusprime619
optimusprime619

Reputation: 764

would suggest you check the permissions for the upload folder and the max size for file uploading in your php.ini... its happened to me many times uploading a file exceeding the limits and not getting an error message.. also the logic of your if else doesn't match as suggested by your previous post..

Upvotes: 0

Kenaniah
Kenaniah

Reputation: 5201

You have a logical error. Your else statement should be part of the inner if statement -- not the outer one.

Upvotes: 3

Related Questions