如何保存多个文件对象解析后端与php sdk


How to save multiple file object to parse backend with php sdk?

我有一个类型为file (multiple)的html输入:

  <input id="image" type="file" name="dog[]" multiple>

我怎么能上传他们与"图像"answers"狗"使用解析关系表解析?

或者有更好的存储关系的方法吗?请建议。由于

代码尝试:

        <?php
        require 'vendor/autoload.php';
        session_start();
        use Parse'ParseClient;
        use Parse'ParseUser;
        use Parse'ParseSessionStorage;
        use Parse'ParseObject;
        use Parse'ParseFile;
        use Parse'ParseGeoPoint;
        ParseClient::initialize('xxx', 'yyy', 'zzz');
        ParseClient::setStorage(new ParseSessionStorage());
        $currentUser = ParseUser::getCurrentUser();
        $filearray = [];
        $count = 0;
        if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
            foreach ($_FILES['dog']['name'] as $f => $name) {
                if ($_FILES['dog']['error'][$f] == 4) {
                    continue; // Skip file if any error found
                }
                if ($_FILES['dog']['error'][$f] == 0) {
                    $tmp = $_FILES['dog']['tmp_name'][$count];
                    $count = $count + 1;
                    $file = ParseFile::createFromData(file_get_contents($tmp), $_FILES['dog']['name']);
                    $file->save();
                    array_push($filearray, $file);
                }
            }
        }
     $dogobj = new ParseObject("Dog");
     $dogobj->setArray("dogimage", $filearray);
     try {
         $dogobj->save();
     }  catch (ParseException $ex) {
         echo 'Failed to create new object, with error message: ' . $ex->getMessage();
     }

编辑::谢谢你的回复,这是我发现的错误

注意:在../index.php的第31行没有定义索引:restaurant_images

警告:第31行./index.php中为foreach()提供的参数无效用objecd: fz1hnCembE创建新对象

到第31行,它指向foreach ($_FILES['restaurant']['name'] as $f => $name) {

我保存的对象成功了,正如你在上面的消息中看到的,图像没有找到

确保表单具有值为multipart/form-data的属性enctype,否则超全局数组$_FILES将为空

<form action="" method="post" enctype="multipart/form-data">
    <input id="image" type="file" name="dog[]" multiple>
    <input type="submit"/>
</form>
<?php
if (isset($_FILES['dog']) === true) {
    $dog = $_FILES['dog'];
    $limit = count(current($dog));
    for ($i = 0; $i < $limit; $i++) {
        $error = $dog['error'][$i];
        if ($error === UPLOAD_ERR_OK) {
            $name = $dog['name'][$i];
            $type = $dog['type'][$i];
            $tmp_name = $dog['tmp_name'][$i];
            $size = $dog['size'][$i];
            //other code
        }
    }
}
?>