How to upload an image to the server with php and at the same time create the folder of each logged in user?

0
 <?php
//Recibimos los datos de la imagen

$nombre_imagen=$_FILES['file']['name'];

$tipo_imagen=$_FILES['file'] ['type'];

$tamagno_imagen=$_FILES['file']['size'];

//aqui va el nombre de la carpeta del usuario logueado
$nombre ='nombreCarpeta';

echo $nombre_imagen;

if ($tamagno_imagen<=100000) {
if ($tipo_imagen=="image/jpeg" ||  $tipo_imagen=="image/jpg" ||  $tipo_imagen=="image/png" )            
{

//Ruta de la carpeta destino en el servidor
$carpeta_destino=$_SERVER['DOCUMENT_ROOT']  . '/Residencia/Imagenes/'.$nombre.'/'; 

if(!file_exists($carpeta_destino)){
mkdir($carpeta_destino,0777,true);
}

//Movemos la imagen del directorio temporal al directorio escogido 

move_uploaded_file($_FILES['file'] ['tmp_name'], $carpeta_destino.$nombre_imagen);
}
else{
echo "Solo se pueden subir formato jpeg,jpe,png";
}
}else{
echo "El tamaño es demasiado grande";
}
?>
<?php
error_reporting(E_ALL);
require_once 'conexion.php';
$obj = json_decode(file_get_contents("php://input"));

 $stmt = $db-> prepare("INSERT INTO  documentos(id_documento,id_puntuacion,documento,fecha_subida)
   VALUES(?,?,?,?)");

$stmt->bind_param('iiss', $obj->id_documento,$obj->id_puntuacion, $obj->documento,$obj->fecha_subida);

$stmt ->execute();
$stmt ->close();

echo "subida exitosa ";
?>
    
asked by Uriel Palacios 24.01.2018 в 18:54
source

0 answers