Re: grabar archivo en servidor
| From: | Daniel BI | Date: | Tue, 18 Jun 2002 13:57:00 +0000 |
| Subject: | Re: grabar archivo en servidor | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-23977@lists.php.net to get a copy of this message | ||
te has fijado algun mometo en el manual?!..
alli donde explica 'file upload'?
aqui lo tienes:
$HTTP_POST_FILES is provided to contain the uploaded file information. This
is still only available if track_vars is turned on, but track_vars is always
turned on in versions of PHP after PHP 4.0.2.
The contents of $HTTP_POST_FILES are as follows. Note that this assumes the
use of the file upload name 'userfile', as used in the example above:
$HTTP_POST_FILES['userfile']['name']
The original name of the file on the client machine.
$HTTP_POST_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An
example would be "image/gif".
$HTTP_POST_FILES['userfile']['size']
The size, in bytes, of the uploaded file.
$HTTP_POST_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on
the server.
Files will by default be stored in the server's default temporary directory,
unless another location has been given with the upload_tmp_dir directive in
php.ini. The server's default directory can be changed by setting the
environment variable TMPDIR in the environment in which PHP runs. Setting it
using putenv() from within a PHP script will not work. This environment
variable can also be used to make sure that other operations are working on
uploaded files, as well. Example 19-2. Validating file uploads
The following examples are for versions of PHP 3 greater than 3.0.16, and
versions of PHP 4 greater than 4.0.2. See the function entries for
is_uploaded_file() and move_uploaded_file().
<?php
if (is_uploaded_file($userfile)) {
copy($userfile, "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$userfile'.";
}
/* ...or... */
move_uploaded_file($userfile, "/place/to/put/uploaded/file");
?>
For earlier versions of PHP, you'll need to do something like the following.
Note: This will not work in versions of PHP 4 after 4.0.2. It depends on
internal functionality of PHP which changed after that version.
<?php
/* Userland test for uploaded file. */
function is_uploaded_file($filename) {
if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
$tmp_file = dirname(tempnam('', ''));
}
$tmp_file .= '/' . basename($filename);
/* User might have trailing slash in php.ini... */
return (ereg_replace('/+', '/', $tmp_file) == $filename);
}
if (is_uploaded_file($userfile)) {
copy($userfile, "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$userfile'.";
}
?>
DBI
----- Original Message -----
From: "Guerrero, Jose" <J.GUERRERO@CGIAR.ORG>
To: <lista@phpes.com>
Sent: Tuesday, June 18, 2002 3:54 PM
Subject: [PHP-ES] grabar archivo en servidor
> Saludos listeros, una preguntita, como hago para guardar un archivo desde
un
> cliente a un servidor ... para expecificar el archivo utilizo:
>
> <input type=file name=archivo>
>
> pero no se como subirlo al servidor.
>
> Muchas gracias
> Bye
>
> Jose
>
> ---------------------------------------------------------------------
> Archivo On-line: http://www.phpes.com/
> via news: news://news.phpes.com/
> Manual PHP en espańol: http://www.php.net/manual/es/
> Para dar de baja la suscripción, mande un mensaje a:
> lista-unsubscribe@phpes.com
>