multiple upload image function php?

前端 未结 2 834
别跟我提以往
别跟我提以往 2021-01-28 19:49

Hi there I want to make a function for me to able upload a multiple image in one submission below are my code structure:

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 20:23

    Try something like this:

    ...
    $images = array();
    foreach (array('image1', 'image2', 'image3') as $name) {
        $images[$name] = new stdClass();
        $images[$name]->fileName = $_FILES[$name]['name'];
        $images[$name]->tmpName  = $_FILES[$name]['tmp_name'];
        $images[$name]->fileSize = $_FILES[$name]['size'];
        $images[$name]->fileType = $_FILES[$name]['type'];
    
        $images[$name]->path = $uploadDir . $images[$name]->fileName;
    
        $result = move_uploaded_file($images[$name]->tmpName, $images[$name]->path);
        if (!$result) {
            echo "Error uploading";
            exit;
        }
    
        $images[$name]->sql = mysql_real_escape_string($images[$name]->path);
    }
    
    $sql="INSERT INTO picture (image1, image2, image3) VALUES ({$images['image1']},{$images['image2']},{$images['image3']})";
    ...
    

提交回复
热议问题