Merge 2 scripts: give error "Notice: Trying to get property of non-object"

0

Hello days ago that I turn to a script and I do not get it. I'm trying to merge 2 scripts;

  • One, is for a record with image upload (saves it in a folder associated with an id with mkdir)
  • The other script is to treat the image with a class (create both a large image and a thumbnail)
  • The idea is that the folder is created for each record id (script 1), and inside each one the big image and the thumbnail are saved (script 2)

    Separately they work, but together I get the following error:

      

    Notice: Trying to get property of non-object ... on line 57

    I do not know much PHP, I do not know where or how to put the second script inside the first one. I would appreciate any explanation for a newbie. If someone knows how to merge the scripts much better. Thanks

    I attach the 2 scripts:

    SCRIPT 1:

    // cargamos el archivo
    if($_FILES["archivo"]["error"]>0){
        echo "Error al cargar archivo"; 
        } else {
    
        $permitidos = array("image/gif","image/png","image/jpeg");
        $limite_kb = 2000;
    
        if(in_array($_FILES["archivo"]["type"], $permitidos) && $_FILES["archivo"]["size"] <= $limite_kb * 1024)
                      {
    
            $file = $_FILES["archivo"]["name"];
            $ext=substr($file, strrpos($file, '.'));  
            $ruta = 'files/'.$id_insert.'/';
            $archivo = $ruta.time().$ext;
    
            //creamos la carpeta y se guarda imagen en directorio.
    
            if(!file_exists($ruta)){ 
                mkdir($ruta);
    
            if(!file_exists($archivo)){
                $resultado = @move_uploaded_file($_FILES["archivo"]["tmp_name"], $archivo);
    
                if($resultado){
                    echo "Archivo Guardado";
                    } else {
                    echo "Error al guardar archivo";
                }
    
                } else {
                echo "Archivo ya existe";               
            }           
            } else {
            echo "Archivo no permitido o excede el tamaño";
        }       
    }   ?>
    

    SCRIPT 2:

    <?php
    include("../src/class/class.upload.php");
    
    $archivo = new upload($_FILES['imagenes']);
    
    if ($archivo->uploaded) 
    {
        $archivo->image_resize              = true; // default is true
        $archivo->image_x                   = 1000; // para el ancho a cortar
        $archivo->image_ratio_y             = true; // para que se ajuste dependiendo del ancho definido
        $archivo->file_new_name_body        = time(); // agregamos un nuevo nombre  
        $archivo->jpeg_quality                = 90;
        $archivo->process('img/content/user/'); 
     echo 'La imagen a sido recortada';
    
    
    
        $archivo->image_resize              = true; // default is true
        $archivo->image_x                   = 100; // para el ancho a cortar
        $archivo->image_ratio_y             = true; // para que se ajuste dependiendo del ancho definido
        $archivo->file_new_name_body        = "t-".time(); // agregamos un nuevo nombre     
        $archivo->process('img/content/user/thumb/');   
     echo 'La imagen a sido recortada';
    
    } 
    else 
    {
        echo 'error : ' . $archivo->error;
    }   
    ?>
    
        
    asked by Mamen Maria 27.09.2017 в 20:01
    source

    0 answers