1

i'm working to an image uploader, but i don't recive any file or information from the html form. So, this is the html code:

<html>
<head><title></title></head>
<body>
    <div id="page">
        <div id="content">
            <form action="pages/post/upload.php" method="post">
                <input type="file" name="userfile" required/>
                <input type="submit" name="send" value="Invia"/>
            </form>
        </div>
    </div>
</body>
</html> 

And this is the php code

<?php
$uploaddir = '/home/pino/Scrivania/Prova/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

print_r($_FILES['userfile']['name']);
print_r($uploadfile);
print_r($_FILES['userfile']['tmp_name']);

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

else {
    echo "Invalid File!\n";
}

echo 'Any information to debug:';
print_r($_FILES);

print "</pre>";
?>

I trid to print any information of the $_FILES array but i don't recive any information.

There are specific information to declare or import into the sources?

mastrobirraio
  • 135
  • 1
  • 9

1 Answers1

4

Please add enctype="multipart/form-data" attribute in <form> tag

enctype='multipart/form-data' - is an encoding type that allows files to be sent through a POST. means that no characters will be encoded. that is why this type is used while uploading files to server.

HTML Code

<html>
<head><title></title></head>
<body>
    <div id="page">
        <div id="content">
            <form action="pages/post/upload.php" method="post" enctype="multipart/form-data">
                <input type="file" name="userfile" required/>
                <input type="submit" name="send" value="Invia"/>
            </form>
        </div>
    </div>
</body>
</html> 
RJParikh
  • 4,096
  • 1
  • 19
  • 36