if isset file php and laravel

Imagick Example

  if(isset( $_FILES["image"] ) && !empty( $_FILES["image"]["name"] ))
            {
            $drive = "drive/temp/";
            $im = new Imagick( $_FILES["image"]["tmp_name"]);
            
            $finalWidth = $_POST['width'];
            $finalHeight = $_POST['height'];
            $size = $_POST['size'];
            
            $name = time().".jpg";//$_FILES["image"]["name"];
            
            $imageprops = $im->getImageGeometry();
                $width = $imageprops['width'];
                $height = $imageprops['height'];
                if($height > $finalHeight){
                $newHeight = $finalHeight;
                $newWidth = ($finalHeight / $height) * $width;
                }else{
                $newWidth = $imageprops['width'];
                $newHeight = $imageprops['height'];
                }
               //$im->resizeImage($newWidth,$newHeight, Imagick::FILTER_MITCHELL, 0.9, true); 
                $im->scaleImage(0, $finalHeight);
                
                if(isset( $_FILES["imagebg"] ) && !empty( $_FILES["imagebg"]["name"] ) )
                {
                    $canvas = new Imagick($_FILES["imagebg"]["tmp_name"]);
                    $canvas->resizeImage($finalWidth, $finalHeight,  Imagick::FILTER_LANCZOS,1);
                }else
                {
                    $canvas = new Imagick();
                    $canvas->newImage($finalWidth, $finalHeight,  $_POST['bgcolor'], 'jpg');
                }     
                $canvas->blurImage(25, 5);
                $pos = ($finalWidth - $newWidth)/2;
                $canvas->compositeImage($im, Imagick::COMPOSITE_OVER,  $pos, 0);
                $canvas->setOption('jpeg:extent', $size.'kb');
                $canvas->setImageFormat( "jpeg" );
            
            //$im->blurImage(25, 5);
            //$im->adaptiveSharpenImage(10,5);
            //$im->unsharpMaskImage(0, 0.5, 1, 0);
            //$im->setImageResolution( 800, 300 );
            //$im->setResolution(800,300);
            //$im->resampleImage  (800,300,imagick::RESOLUTION_PIXELSPERINCH,1);
            //$im->cropThumbnailImage( 800, 300 );
            //$im->setImageCompressionQuality(70);
            //$im->setImageCompression(true);
            //$im->scaleImage(0, 300);
            //$im->adaptiveResizeImage(800,300);
            //$im->liquidRescaleImage(800, 300, 3, 18);
            //$im->resizeImage(800, 300,  Imagick::FILTER_LANCZOS,1);
            //$im->sharpenImage(0, 3);
            //$im->adaptiveBlurImage(5, 1, 0);
            
            if (file_exists($drive.$name)) {
                try{
                    unlink($drive.$name);
                }
                catch(Exception $ex)
                {
                echo $ex->getMessage()."Adi";
                }  
            }
            $canvas->writeImage($drive.$name);
            //print_r($canvas->identifyImage());
            return redirect("image-resizer")->withSuccess('drive/temp/'.$name);         
            }
            
        return view('imageresizer',['name'=>'drive/temp/'.$name,'title'=>'Online Image Resizer','isUpload'=>1]);

get file temp path laravel from request file for imagick

get file temp path laravel from request file for imagick

  $file = $request->file('image');
  $im = new Imagick( $file->getPathName());

In Core PHP

 $im = new Imagick( $_FILES["image"]["tmp_name"] );

how to use ckeditor in html

<script src="https://cdn.ckeditor.com/ckeditor5/40.0.0/classic/ckeditor.js"></script>
<textarea class="form-control" name="description" id="description" rows="10"><?php echo openssl_decrypt($notes[$key]['description'],"AES-128-ECB",$enc_key);//base64_decode($notes[$key]['description']);?></textarea>

<script>              
    ClassicEditor
        .create( document.querySelector( '#description' ),
        {
          ckfinder: {
            //uploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json'
        },
      toolbar: {
       items: [
        'selectAll', 'undo', 'redo', 'bold', 'italic', 'blockQuote', 'link', 'heading', 'imageTextAlternative', 'toggleImageCaption', 'imageStyle:inline', 'imageStyle:alignLeft', 'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:alignBlockLeft', 'imageStyle:alignBlockRight', 'imageStyle:block', 'imageStyle:side', 'imageStyle:wrapText', 'imageStyle:breakText', 'indent', 'outdent', 'numberedList', 'bulletedList', 'mediaEmbed', 'insertTable', 'tableColumn', 'tableRow', 'mergeTableCells'
    ],
    shouldNotGroupWhenFull: false
      },
        })
        .then( editor => {
       // console.log( Array.from( editor.ui.componentFactory.names()));
    })
    .catch( error => {
            console.error( error );
        });
</script>

number to month name in php

How to get number to month name in php

Method 1

$monthNum  = 3;
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F'); // March

Method 2

$monthNum  = 3;
$monthName = date('F', mktime(0, 0, 0, $monthNum, 10)); // March

how to install imagick php extension ubuntu

sudo apt install php php-common gcc
sudo apt install imagemagick

To install imagick

sudo apt-get install php-imagick

After you can enable on phph.ini

extension=imagick.so
php -m | grep imagick

Last, just restar apache:

sudo service apache2 restart

find string in string php

str_contains(string $haystack, string $needle): bool

str_contains — Determine if a string contains a given substring

<?php
$string = 'The lazy fox jumped over the fence';

if (str_contains($string, 'lazy')) {
    echo "The string 'lazy' was found in the string\n";
}

if (str_contains($string, 'Lazy')) {
    echo 'The string "Lazy" was found in the string';
} else {
    echo '"Lazy" was not found because the case does not match';
}

?>

automated task php

PHP natively doesn’t support automating tasks, you have to build a solution yourself or search google for available solutions. If you have a frequently visited site/page, you could add a timestamp to the database linking to the file, when visiting your site in a chosen time (e.g. 8 in the morning) the script (e.g. deleteOlderDocuments.php) runs and deletes the files that are older.

PHP operates under the request-response model, so it won’t be the responsibility of PHP to initiate and perform the scheduled job. Use cron, or make your PHP site to register the cron jobs.

use array with where in laravel

$assignquestion = DB::table('assign_question')->where('user_id',$user_id)->get();
    $assignq = array();
    foreach($assignquestion as $assign)
    {
    $assignq = array_merge($assignq,json_decode($assign->question_ids,true));
    }
    $data = DB::table('question_master')->whereIn('id',$assignq)->paginate(50);

switch PHP version from 8.0 to 7.4  on ubuntu

sudo a2dismod php8.0
sudo a2enmod php7.4
sudo service apache2 restart
sudo a2dismod php7.4
sudo a2enmod php8.0
sudo service apache2 restart
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
sudo service apache2 restart