Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel copy image with new name

 
//contact_ids is ['10','11',''12], i mean multiple value;contact_ids data type is json so that we will use json_decode()

$sharedContact = SharedContact::all();
$contacts = Contact::whereIn('id',json_decode($sharedContact->contact_ids))->get();

            foreach ($contacts as $contact){
				// copying the old record
                $sharedContact = $contact->replicate();
                
				//change name for image and saving in local storage
                $newName = 'share_'.time().'_'.$contact->photo;
                $newPathWithName = 'public/photo/'.$newName;
                
                if (Storage::copy('public/photo/'.$contact->photo , $newPathWithName)) {
//                    dd("success");
                    $sharedContact->photo = $newName;
                    $sharedContact->user_id = Auth::id();
                    $result = $sharedContact->save();
                }
                dd($result);
                
            }
Comment

laravel copy image

//$contact->photo is file name with extension -> dljfkaldla.jpg 
$newName = 'copy_'.time().'_'.$contact->photo;
                $newPathWithName = 'public/photo/'.$newName;
                if (Storage::copy('public/photo/'.$contact->photo , $newPathWithName)) {
                dd("success");
                }
Comment

PREVIOUS NEXT
Code Example
Php :: how to create resource controller in laravel 
Php :: create symfony demo app 
Php :: naming the routes in laravel 
Php :: php flatten array 
Php :: laravel passport Route [login] not defined 
Php :: laravel collection to json 
Php :: last insert id mysqli 
Php :: how to run a php file in xampp 
Php :: python to php converter online 
Php :: laravel custom validation rules 
Php :: Compiling multiple CSS into ONE CSS with Laravel MIX 
Php :: remove square brackets from string php 
Php :: laravel debugbar false 
Php :: math functions and predefined constants php 
Php :: php array push 
Php :: laravel eloquent get one column value 
Php :: php date() 
Php :: php one line if without else 
Php :: laravel resource api 
Php :: how to create cookie in laravel 
Php :: laravel logout after password change 
Php :: delay queue laravel 
Php :: php number multiple of 
Php :: laravel public static variable 
Php :: install multiple php versions windows xampp 
Php :: catch warning php 
Php :: quitar html con laravel 5 
Php :: how to check ia folder if no have files in php 
Php :: remove duplicate characters in a string in php 
Php :: php namespaces 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =