0
votes

HTML FORM

<form name="nv" method="post" action="#" enctype="multipart/form-data">
<table>
<tr>
<td>Photo:</td>
<td><input name="photo" type="file" size="58"></td>
</tr>


<tr>
<td><input name="res" type="reset" value="reset"></td>
<td><input name="sub" type="submit" value="s'enregistrer"></td>
</tr>
</table>
</form>

PHP

$file_result = "";
if($_FILES["photo"]["error"]>0){

    $file_result =" il y a un error lors de la telechargement de la photo, error : <br />". $_FILES["photo"]["error"];

    }else{

        $path = "C:\\Program Files (x86)\\EasyPHP-5.3.9\\www\\2011pr\photos\\";

        move_uploaded_file($_FILES["photo"]["name"],$path);

        $file_result = $_FILES["photo"]["name"] . "  est bien telecharge a dans le serveur";
        }

    echo " <br /> ". $file_result." <br /> ";

it gives me this error:

Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\Program Files (x86)\EasyPHP-5.3.9\www\2011pr\nouveau.php on line 129

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Program Files (x86)\EasyPHP-5.3.9\tmp\phpF33.tmp' to 'C:\Program Files (x86)\EasyPHP-5.3.9\www\2011pr\photos\' in C:\Program Files (x86)\EasyPHP-5.3.9\www\2011pr\nouveau.php on line 129

4
Just read error message ...Phantom

4 Answers

0
votes

The second parameter of move_uploaded_file() requires a file path, not a folder path. Therefore, you need to change

move_uploaded_file($_FILES["photo"]["name"],$path);

to

move_uploaded_file($_FILES["photo"]["tmp_name"],$path.$yourNewFilename);

Also, $_FILES["photo"]["name"] is this file name like picture.jpg. $_FILES["photo"]["tmp_name"] is the temporary file.

0
votes

move_uploaded_file() requires a destination FILENAME, you're just providing a path. e.g.

move_uploaded_file($foo, '/some/directory/'); // illegal
move_uploaded_file($foo, '/some/directory/kittens.jpg'); // valid - specifying a filename.

In other words, RTFError.. PHP TOLD you exactly what the problem is.

0
votes

The answer is in your warning:

The second argument to copy() function cannot be a directory in C:\Program Files (x86)\EasyPHP-5.3.9\www\2011pr\nouveau.php on line 129

In effect try a different directory. Not a good idea to be writing code in your Program Files anyway. Make a directory in your Documents folder or under your username folder instead.

0
votes

As the error suggests, the second parameter of move_uploaded_file() should be the full path to the file itself - including the new filename.

See here http://uk3.php.net/move_uploaded_file