jeudi 22 juin 2017

Using values as a validation check in laravel

I have created a script which takes a zip files apart and counts how much files are in the zip. For a validation check I need to use the INT the function puts out and do a if statement with it, How can I make this work?

$zipFile = $request->file('fupload');
    $templatename = $request->input('template_name');
    $file_to_open = $request->file('fupload')->getRealPath();
    $target = storage_path();

    $zip = new \ZipArchive();
    //$x = $zip->open($file_to_open);
    // if($x === true) {
    //     $zip->extractTo($target);
    //     $zip->close();
    if ($zip->open($file_to_open) == TRUE) {

        for ($i = 0; $i < $zip->numFiles; $i++) {
            $filename = $zip->getNameIndex($i);

            if ( stristr($filename, '__MACOSX') === FALSE )
            {
                //$this->files[$i] = $filename;
                $path_parts = pathinfo($filename);

                if ( isset($path_parts['extension']) && !isset( $this->extensions[$path_parts['extension']] ) )
                {
                    $this->extensions[$path_parts['extension']] = 1;
                } else if ( isset($path_parts['extension']) )
                {
                    $this->extensions[$path_parts['extension']] = $this->extensions[$path_parts['extension']] + 1;
                }

                if ( isset($path_parts['extension']) && ($path_parts['extension'] == 'html' || $path_parts['extension'] == 'htm' ) )
                {
                    $this->html = $zip->getFromName($filename);
                    $this->files[] = (object) [ 'filename' => basename($filename), 'contents' => $zip->getFromName($filename)];
                } else if ( isset($path_parts['extension']) ) {
                    $this->files[] = (object) [ 'filename' => basename($filename), 'contents' => $zip->getFromName($filename)];
                }


            }
        }

        echo '<pre>';
        var_dump($templatename, $this->extensions);
        $this->validateZipfiles();

    }
    unlink($file_to_open);
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tw3LBp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire