Home  >  Q&A  >  body text

Multi-image upload, how to write the upload path into the database

I have implemented multiple image uploads. The uploaded folders all have images, but there is only one piece of data uploaded to the database. What should I do? How should I write the controller?

html code<input type=" file" name="image[]" /> <br>

How to write the controller, please guide

RAULRAUL2663 days ago1496

reply all(2)I'll reply

  • RAUL

    RAUL2017-07-28 15:33:37

    public function upload(){

    // Get the form upload file, for example, uploaded 001.jpg

    $files = Request::instance()->file('image');

    foreach($files as $ file){

    $info = $file->move('upload');

    }

    print_r($files);exit;

    $infos = $info->getFilename();

    $date=date("Ymd",time());

    $data = input('post');

    $data['path'] = ' /upload/'.$date.'/'.$infos;

    $ret = model('Photo')->saveALL($data['path']);

    $this->redirect('admin/product/index');

    }

    How do I get the image name of the multi-dimensional array in a loop

    The following is the printed

    Array

    (

    [0 ] => thinkFile Object

    (

    [error:thinkFile:private] =>

    [rule :protected] => date

    [validate:protected] => Array

    (

    )

    [isTest:protected] =>

    (

    [key] => image

    [name] => 5.jpg

    [type] => image/jpeg

    [tmp_name] => C:wamptmpphpC8C2.tmp

    [error] = > 0

    [size] => 40090

    )

    [hash:protected] => Array

    (

    )

    [pathName:SplFileInfo:private] => C: wamptmpphpC8C2.tmp

    [fileName:SplFileInfo:private] => phpC8C2.tmp

    [openMode:SplFileObject:private] => r

    [delimiter:SplFileObject:private] => ,

    [enclosure:SplFileObject :private] => "

    )

    reply
    0
  • PHP中文网

    PHP中文网2017-07-28 15:27:37

    You can see the data structure after printing the data. Just process it according to this structure


    reply
    0
  • Cancelreply