I have html input with a file of type (multiple):
<input id="image" type="file" name="dog[]" multiple>
How can I upload them to Parse with the βImagesβ and βDogβ tables using the parse ratio?
Or is there a better way to keep the attitude? Please advise. thanks
The code tried:
<?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(); }
EDIT :: Thanks for the answer, this is the error I found
Note: Undefined index: restaurant_images in ../ index.php on line 31
A warning. Invalid argument provided by foreach () in .. /index.php on line 31 New object created using objectId: fz1hnCembE
On line 31, this refers to foreach ($_FILES['restaurant']['name'] as $f => $name) {
The object I saved successfully, as you see in the message above, the image was not found
source share