insight's avatar

File upload in an array not work

Dear Friends, I am trying to upload PDF file(s) through a dynamic upload field . The file name is stored but physical file is not stored in folder. my code is

 $uploads = $request->file('uploadworkexperience');
            foreach ($organizations as $key => $organization) {
                $data = [
                  'app_id' => $app_id,
                  'exp_organisation' => $organization,
                  'exp_designation' => $designations[$key],
                  'exp_job_role' => $jobroles[$key],
                  'exp_responsibilities' => $responsibilities[$key],
                  'exp_work_from' => $fromdates[$key],
                  'exp_work_to' => $todates[$key],
                  'exp_certificate' => $uploads[$key]->storeAs('public/work_experience', $uploads[$key]->getClientOriginalName(), ['force' => true])
                ];
                DB::table('ksitm_work_experience')->insert($data);
              }

$uploads array is like

array:2 [ // app\Http\Controllers\ApplicantController.php:210
  0 => Illuminate\Http\UploadedFile {#284
    -test: false
    -originalName: "sample.pdf"
    -mimeType: "application/pdf"
    -error: 0
    #hashName: null
    path: "C:\xampp\tmp"
    filename: "php6EDD.tmp"
    basename: "php6EDD.tmp"
    pathname: "C:\xampp\tmp\php6EDD.tmp"
    extension: "tmp"
    realPath: "C:\xampp\tmp\php6EDD.tmp"
    aTime: 2023-06-12 08:35:08
    mTime: 2023-06-12 08:35:07
    cTime: 2023-06-12 08:35:07
    inode: 32651097298582766
    size: 3028
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\xampp\tmp\php6EDD.tmp"
  }
  1 => Illuminate\Http\UploadedFile {#285
    -test: false
    -originalName: "sample.pdf"
    -mimeType: "application/pdf"
    -error: 0
    #hashName: null
    path: "C:\xampp\tmp"
    filename: "php6EEE.tmp"
    basename: "php6EEE.tmp"
    pathname: "C:\xampp\tmp\php6EEE.tmp"
    extension: "tmp"
    realPath: "C:\xampp\tmp\php6EEE.tmp"
    aTime: 2023-06-12 08:35:08
    mTime: 2023-06-12 08:35:07
    cTime: 2023-06-12 08:35:07
    inode: 15199648742522281
    size: 3028
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\xampp\tmp\php6EEE.tmp"
  }
]

why this happen. I am working in localhost machine .

Thanks

Anes P A

0 likes
3 replies
shariff's avatar

@insight try keeping name before uploading a file

$uploads[$key]->store('work_experience','public');

or 

$name = 'name_of_the_file';

$uploads[$key]->storeAs(
    'work_experience',
    $name,
    'public'
);

to see in public directory you should run

php artisan storage:link
insight's avatar

@shariff Don't use the php artisan storage:link .. It make me great error . so I started a new installation and now works fine.... I have issue in showing server validation . I will post it as another thread. Please help there...

Thanks

Anes P A

Snapey's avatar

how does the files array of 0,1,2 etc relate to the organization?

Please or to participate in this conversation.