Using the official Parse PHP SDK, it’s quite easy to upload a file to Parse. I’ve received a few requests for a tutorial to cover this particular issue, so here it is. I’ve used Parse PHP SDK v1.0.4 for this tutorial, but it will work with older versions too.
Using a simple HTML form and a few lines of PHP, you can upload a file to Parse. As we’re using PHP, the file is first uploaded to your server (in temporary space) and then sent to Parse.
When you create your Parse Class, make sure one column is of type File
. In my example, the class TestObject
has two columns: foo
of type String
, and image
of type File
.
The Code:
The Output:
After selecting a file to upload and submitting it, the above code will output the objectId of the saved object, and the link to the uploaded file:
In Parse, the class should show the uploaded file too (in my example, under the image
column). You can click on the file name here to show the uploaded file too.
If you experience any issues with the above code, please let me know in the comment section below.
Thanks Niraj!
this works perfectly for image uploading and for music uploading I added this added this line below.
$file = ParseFile::createFromData( file_get_contents( $_FILES[‘mymusic’][‘tmp_name’] ), “newmusic.mp3” );
HI Niraj,
I am trying this code but it’s showing the error about SSL certification.
How to solve this.
Are you getting this error on a local environment or on your production env?
I’m having this on my local environment
To fix the issue, you have two options: 1) setup SSL on your local environment using a self-signed certificate. The setup for this will depend on what server software you use. 2) Edit the
ParseClient.php
file to add the following line to the_request()
method:curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);
Please don’t use this in production environment.
I tried the other option with cacert.pem that works fine for me..
Hello Niraj:
I have this error : SSL certificate problem: unable to get local issuer certificate.
I’m working on a local environment (xampp)
Just answered the same problem for another reader
I did the both solution and I still have the same error. I have this error when I do the file->save()
I put the line: curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false); in the _request function in the ParseClient.php file but the same error : SSL certificate problem: unable to get local issuer certificate.
I put the line in ParseClient.php like this :
$rest = curl_init();
curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);
but still :
Failed to create new object, with error message: SSL certificate problem: unable to get local issuer certificate