Upload images and pdf files with php and mysql

1

Hi, I have this code that I have been able to assemble, I only upload the images, but when I select a pdf file, it is not saved in the indicated folder, they could tell me what my error would be, this is what I have

function AgregarRecepcionCertificado(){
    $Recepciones= new Recepciones();  
    $tipoArchivo=explode("/",$_FILES["archivo"]["type"]);
    $ubicacion="ARCHIVOS_FOODZ\CERTIFICADO_SENASA";
    $Recepciones->n_item=$_REQUEST["item"]; 
    $Recepciones->NumRecepcion=$_REQUEST["NumRecepcion"];   
    $Recepciones->IdProveedor=$_REQUEST["IdProveedor"];     
    $Recepciones->IdCoordinador=$_REQUEST["IdCoordinador"];     
    $Recepciones->CodProducto=$_REQUEST["CodProducto"];     
    $Recepciones->Chofer=$_REQUEST["Chofer"];       
    $Recepciones->NomImagenR=$ubicacion."/".$_REQUEST["NomImagen"].'.'.$tipoArchivo[1];     
    $Recepciones->NomImagen=$_FILES['archivo']['name'];     


    $nombre_img=$_FILES['archivo']['name'];
    if (($_FILES['archivo']['name'] == !NULL) && ($_FILES['archivo']['size'] <= 500000)) 
    {
        //indicamos los formatos que permitimos subir a nuestro servidor
        if (($_FILES["archivo"]["type"] == "image/gif")
            || ($_FILES["archivo"]["type"] == "image/jpeg")
            || ($_FILES["archivo"]["type"] == "image/jpg")
            || ($_FILES["archivo"]["type"] == "image/png")
            || ($_FILES['archivo']['type'] == "application/pdf")
            )
        {
            //$foto=$ubicacion."/".$cant.".jpg";
            $NomImagenR=$ubicacion."/".$_REQUEST["NomImagen"].'.'.$tipoArchivo[1];
            // Muevo la imagen desde el directorio temporal a nuestra ruta indicada anteriormente
                move_uploaded_file($_FILES['archivo']['tmp_name'],$NomImagenR);
        } 
        else 
        {
        //si no cumple con el formato
            echo "No se puede subir una imagen con ese formato ";
        }
    } 
    else 
    {
    //si existe la variable pero se pasa del tamaño permitido
    if($_FILES['archivo']['name'] == !NULL) echo "La imagen es demasiado grande "; 
    }       
    $data=$this->recepciones->RegistrarRecepcionCertificado($Recepciones);
    echo(json_encode($data)); 

}   
    
asked by Vanesa Claros 19.04.2018 в 19:49
source

1 answer

2

I found the error here ($ _FILES ['file'] ['size'] < = 500000) (I used this because I was only uploading images first), I was limiting the size of the file, and the .pdf I was trying loading was larger, and I was not showing the size error, until I checked in browser developer mode ..

    
answered by 19.04.2018 / 20:11
source