I'm working in a real state project, I would like them to upload pictures and description of apartment.
The description comes with a form plenty of questions, those question are stored in a DB, the DB itself generates a number for every upload. This is nwhat I have reach by the moment.
What I need is a form like the one I attach, able to rename the pictures an store them in a directory and able also to store this new name in one of the cells related to the apartment in a why that I can call the picture afterwords.
For example:
A user is uploading data about an apartment, the DB gives this apartment number 5678, when finished with the data wants to upload 3 images, (maximun 5) those images are renamed
5678-1.jpg
5678-2.jpg
5678-3.jpg
and those names are also stored in the table Photos in the database, in the cells photo1, photo2, photo3.
Clear enough?
Maybe a little messy, but I'm getting realy crazy!
<?PHP
$path = "fotos/";
$max_size = 200000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "La foto es demasiado grande\n";
exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "Este nombre de archivo ya existe\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "Envio de imagen fallido<br>\n"; exit; } else { echo "La imagen ha sido enviada<br>\n"; }
echo "Nombre de la foto: ".$HTTP_POST_FILES['userfile']['name']."\n";
echo "Tamaño de la foto: ".$HTTP_POST_FILES['userfile']['size']." bytes\n";
echo "Tipo de archivo: ".$HTTP_POST_FILES['userfile']['type']."\n";
} else { echo "Este archivo no es un archivo JPG o GIF\n";
exit; }
}
?>