-
-
Save pietromalerba/bdfbd8ab40feca2bbebc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// define location of Parse PHP SDK, e.g. location in "Parse" folder | |
// Defaults to ./Parse/ folder. Add trailing slash | |
define( 'PARSE_SDK_DIR', './Parse/' ); | |
// include Parse SDK autoloader | |
require_once( 'autoload.php' ); | |
// Add the "use" declarations where you'll be using the classes | |
use Parse\ParseClient; | |
use Parse\ParseObject; | |
use Parse\ParseException; | |
use Parse\ParseFile; | |
// init Parse | |
ParseClient::initialize('xxx', 'yyy', 'zzz'); | |
// see if we have a file | |
if ( isset( $_FILES['image'] ) ) { | |
// save file to Parse | |
$file = ParseFile::createFromData( file_get_contents( $_FILES['image']['tmp_name'] ), $_FILES['image']['name'] ); | |
$file->save(); | |
// save something to class TestObject | |
$testObject = ParseObject::create( "TestObject" ); | |
$testObject->set( "foo", "bar" ); | |
// add the file we saved above | |
$testObject->set( "image", $file ); | |
$testObject->save(); | |
// get the object ID | |
echo 'Object Saved with ID: <strong>' . $testObject->getObjectId() . '</strong>.<br/>'; | |
// get the file URL | |
echo 'File URL: <a href="' . $file->getURL() . '" target="_blank">' . $file->getURL() . '</a>'; | |
} else { | |
?> | |
<form action="upload.php" method="post" enctype="multipart/form-data"> | |
Select image to upload: | |
<input type="file" name="image"> | |
<input type="submit" value="Upload Image" name="submit"> | |
</form> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment