Inserting files image array into a database

前端 未结 1 813
野性不改
野性不改 2021-01-28 13:13

I am creating a stock form which includes up to 20 image files. When uploading the images to the server i need to change the name and also insert them into a database so that it

相关标签:
1条回答
  • 2021-01-28 13:48

    Don't harcode the indices of the upload array. Instead build you array dynamically:

    $i = 0;
    $uploads = array();
    if(move_uploaded_file($file_tmp, $file_destination)) {
        $uploaded[$position] = $file_destination;
        $image = ($i==0) ? 'image' : 'image_'.$i;
        $uploads[$image]=$uploaded;
        $i++;
    }
    

    Then use it:

     $insert = DB::getInstance()->insert('stock', $uploads);
    
    0 讨论(0)
提交回复
热议问题