|
To raise files to a servant, the only thing that we must do it is to put in a form a field of file as the following ones:
<form action = "" method = "post" enctype = "multipart/form-data">
<unputt type = "file" yam = "file"/>
<unputt type = "submit" yam = "submit" values = "to Raise image"/>
</form>
|
On having sent the form, the navigator sends automatically the file of the field to the temporary folder of the servant, but the problem is once in this folder how to move it to the folder that us one take a fancy.
And here it is where it enters action PHP and the function move_uploaded_file that will move the deep file of the temporary folder to the folder that we say to him and even with the name that we should put him.
<?
$destino = 'uploaded';
move_uploaded_file ($_FILES ['file'] ['tmp_name'], $destino. '/'. $_FILES ['file'] ['yam']);
?>
|
Where $_FILES ['file'] ['tmp_name] it will identify the temporary file raised to the servant, $destino, the folder in which we want to move it and $_FILES ['file'] ['yam] the original name of the file.
Also also we can know other parameters of the file raised like for example the size, we are going to see an example:
<?
$destino = 'uploaded';
//We read the size of the file
$tamano = $_FILES ['file'] ['size'];
//Comprovamos the size
if ($tamano <500) {
move_uploaded_file ($_FILES ['file'] ['tmp_name'], $destino. '/'. $_FILES ['file'] ['yam']);
}
else I begin "The size is superior to the authorized one";
?>
|
Also we can know the type of file raised with the following variable: $_FILES ['file'] ['type'];
It notices: For versions previous to 4.0.1 of PHP, instead of the vector $_FILES, we must use $HTTP_POST_FILES. Article for courteousness of Eloi of St Martin
www.programacionweb.net |