I'm using the Parse PHP SDK and trying to upload an image. The file successfully saves, however the URL for the file returned by the getUrl() ParseFile method returns a 403 forbidden when I try to view it. Viewing the file via the Parse data browser also returns a 403 error. I'm using Laravel, and have tried several different methods:
1) Upload the file to parse, save the object against the user and then access the File via the getURL() method:
$contents = Input::file('profile_picture');
$file = ParseFile::createFromData($contents, "profilePicture_".$contents->getClientOriginalName());
Auth::user()->set('profilePicture', $file);
// In My View
<img src="{{Auth::user()->get('profilePicture')->getUrl()}}"/>
The URL returned returns a 403 forbidden.
2) Upload the file to Parse and store the URL against the user
$contents = Input::file('profile_picture');
$file = ParseFile::createFromData($contents, "profilePicture_".$contents->getClientOriginalName());
Auth::user()->set('profilePicture', $file->getUrl());
// In My View
<img src="{{Auth::user()->get('profilePicture')}}"/>
I have also tried both the above using:
$file = ParseFile::createFromData($contents, "profilePicture".$contents->getClientOriginalExtension());
An example of the URL being returned looks like:
http://files.parsetfss.com/2ed712aa-99d8-4df1-8100-a1f907042d43/tfss-37d8f8e3-b8fc-4980-8d45-4a24957a5dc0-profilePicturepong.jpg
It was actually a case of me using the wrong method. I should have been using createFromFile
Related
I'm trying to show a series of pictures and comments in a document with OpenTBS. The pictures are hosted on a local webserver. The data is in an array.
In the resulting document the text lines are rendered as expected, but the sample image is not changed.
When I copy paste the url location in my browser it shows a picture without problem.
With setting "$NoErr = false;" there is no error message.
What am I doing wrong?
My template:
[imgs; block=begin]
<a sample image>[imgs.url;ope=changepic]
Location: [imgs.url]
Description: [imgs.txt]
[imgs; block=end]
In my PHP code (a.o.):
$imgs = array();
$imgs[] = array('url'=>'http://192.168.0...', 'txt'=>'Sample 1');
$imgs[] = array('url'=>'http://192.168.0...', 'txt'=>'Sample 2');
$OOo->MergeBlock('imgs', $imgs);
$OOo->Show(OPENTBS_DOWNLOAD, 'file.docx');
Update: same problem when I change the url to some public available images on the web.
OpenTBS uses the following 3 functions in order to instert a picture into the current document :
file_exists()
filesize()
file_get_contents()
While the function file_get_contents() usually works for an URL, the tow other functions file_exists() and filesize() return false despite the PHP documentation says they can supports http protocol.
So the behavior you have probably come from file_exists() returning false for you url.
The workaround I suggest is to download the file as a temporary file, then insert it into the document.
I am trying to develop a login to my website functionality with Facebook account using Facebook Graph API.
I am in trouble to retrieve profile image of logged in user because Facebook returns URL but when I try it on the navigator it says that it needs permission to download it.
For example the URL:
https://platform-lookaside.fbsbx.com/platform/profilepic/?asid......
PS : I make the 3 points
I want to know if there is any method to get a correct URL to save it in the database or if there is any method to download the image with PHP, I tried this on my end, but no success.
$img = file_get_contents($dataata['picture']['url']);
$file = '/img/test.jpg';
file_put_contents($file, $img);
Message returned is :
file_put_contents(/img/test.jpg): failed to open stream: No such file
or directory
Any solution?
Have tried the API call as listed on Podio dev site to upload a file and I am not getting much joy.
I am trying to "Upload a file" in the first instance using the POST operation and passing the json with the source url to the endpoint as specified.
I can use other methods just fine but since there is little in the way or error feedback I am stuck I keep getting error 404
I have used - https://developers.podio.com/doc/files/upload-file-1004361
(have tried both GET & POST)
image of method with error i get
Upload file method that you are trying to use (https://developers.podio.com/doc/files/upload-file-1004361) is expecting file path which is supposed to be local file but not url.
Here is example of how it should be used:
http://podio.github.io/podio-php/api-requests/
$file = PodioFile::upload($path_to_file, $filename_to_display);
print 'File uploaded. The file id is: '.$file->id;
Here is another example on how to work with files:
https://developers.podio.com/examples/files
I'm using file put content to save my image to the server, but I get an error and the image is not saved .
I am getting the base64 string from android app, I decode it and pass it on for saving. My php script is in this location (example):
www.aaa.com/test
I want to save the photos to:
www.aaa.com/test/photos
What I have:
$name = "image123.png";
$data = base64_decode($fldPostPhoto);
file_put_contents("photos/".$name,$data);
uploading image with file_put_contents make 0 byte file.
here is the code that I use. I extract facebook image url and put it into web server.
$fb_image_url = 'https://example.com/229282.jpg'
$filename = substr($fb_image_url, strrpos($fb_image_url, '/') + 1);
file_put_contents('upload/user_pic/original/'.$filename, file_get_contents($fb_image_url));
after I do this, the server receive file name successfully, but it is 0 bytes.
I checked php.ini, and allow_url_fopen is ON.
uploading folder permission is also fine.
To copy images from facebook, script/php program require permission for same. if program/ FB API dont passes validation/permission check, FB dont allows to download any image.
Its looks like your Application don't have permission to download/copy this image from Facebook that's why your getting 0 bytes.
Try giving PUBLIC access to image and keep FB account logged in while coping image
I just put that URL into the browser:
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/274661_1171545457_6475606_n.jpg
And received 404 Not Found in response. This would explain why you get empty file locally. I strongly suggest that you load the data first, verify what you received and then, if validation passes, save it locally.
here is the solution.
I had a problem with facebook profile address.
$fb_image_url = 'https://graph.facebook.com/'.$facebook_id.'/picture?type=large';
$filename = $fb_id.'_'.time().'.jpg';
$result = file_get_contents($fb_image_url);
file_put_contents('upload/user_pic/original/'.$filename, $result);
with this_ it worked fine. Yeah! Thank you everyone!