Ankit Sachan Ankit Sachan - 11 months ago 68
PHP Question

php : unable to upload file to the server

hey I am not much of a PHP coder

I am using following to upload file to server acn any body help me whats wrong with this code


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

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "{$file}";


Thanx in advance

Answer Source

I don't see anything wrong with the PHP code, though without an error it is difficult to tell what is happening.

Somethings which could cause uploads not to work, and which may not return errors:

  1. Ensure you have enctype="multipart/form-data in the form tag:

    <form enctype="multipart/form-data" action="__URL__" method="POST">

  2. Make sure PHP is accepting the input, by adjusting the following PHP ini variables:

  3. Finally, ensure that permissions are properly set for both the temp upload folder ( and the folder you are moving files to. If it is a Windows server you might also run into an inheritance issue which will require you to change the default upload directory.