Preparing GD dynamic image for upload - php

How can I prepare a dynamic image created by GD for upload?
I created a php script to create dynamic images based on the userid (EX: www.mywebsite.com/image/124.png <== that should show the user 124 info)
Now I need to upload it to Facebook with this script :
$photo_details = array(
'message'=> $message
);
$file = "$_GET[id].png";
$photo_details['image'] = '#/home/username/public_html/image/' . $file;
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
When I use the upload script that way I get this error:
Fatal error: Uncaught CurlException: 26: failed creating formpost data
But If I uploaded 124.png to /image/ directory and and tried the same code again with using the ID 124 it works just fine. After a long research I came to conclusion the problem relay in the dynamic part since it works just fine with static images. How can I solve this problem?
Thank you so much for all the help.

Looks like the script tries to read the file directly from the filesystem instead of running the image generating script. You can solve this by setting $photo_details['image'] = 'http://www.mywebsite.com/image/'.$file; if Facebook class allows this kind of file opening.

Related

PHP: Call to undefined method PhpOffice\PhpSpreadsheet\Reader\Xlsx\Styles::setWorkbookPalette()

I am attempting to use an HTML form to display a "summary" section that contains an array of the headers (first row) of a spreadsheet file when the file is chosen and supplied to the File Input field of the form.
The AJAX request sends the file to the Wordpress backend where it is processed using wp_handle_upload, a PHP script attempts to identify the file type and create the appropriate Reader, then loads the file into the reader.
From here I would like to write some parsing script, unlink the file to get rid of PII for privacy compliance, then return the relevant information to the AJAX request.
public function tjg_csbs_ajax_get_spreadsheet_summary($file) {
// Pass file to wp_handle_upload
$upload = wp_handle_upload($file, array('test_form' => false));
// File type using IOFactory::identify()
$file_type = IOFactory::identify($upload['file']);
$reader = IOFactory::createReader($file_type);
// Pass upload to reader
try {
$spreadsheet = $reader->load($upload['file']);
unlink($upload['file']);
} catch (Exception $e) {
unlink($upload['file']);
wp_send_json_error('Error loading file: ' . $e->getMessage());
die();
}
}
I've verified that IOFactory::identify() and IOFactory::createReader() seem to be working, but when I call $reader->load() I am hitting a brick wall over and over.
The file is successfully being uploaded through $_FILES via the AJAX request
wp_handle_upload successfully handles the file and the file is visible in the wordpress uploads folder
Different spreadsheet files other than the testing file are returning the same error
Here's the error output:
Fatal error: Uncaught Error: Call to undefined method PhpOffice\PhpSpreadsheet\Reader\Xlsx\Styles::setWorkbookPalette()
in /home1/wp-content/plugins/tjg-csbs/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 566
Call stack:
PhpOffice\P\R\Xlsx::loadSpreadsheetFromFile()
wp-content/plugins/tjg-csbs/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/BaseReader.php:166
PhpOffice\P\R\BaseReader::load()
wp-content/plugins/tjg-csbs/public/class-tjg-csbs-public.php:216
Tjg_Csbs_Public::tjg_csbs_ajax_get_spreadsheet_summary()
wp-content/plugins/tjg-csbs/public/class-tjg-csbs-public.php:186
Tjg_Csbs_Public::tjg_csbs_ajax_primary()
wp-includes/class-wp-hook.php:307
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:331
WP_Hook::do_action()
wp-includes/plugin.php:476
do_action()
wp-admin/admin-ajax.php:187
I've successfully used PHPSpreadsheet before with classic POST requests without encountering this error when not involving Javascript or AJAX in a different use case.
Any ideas where to check next to get this resolved? Huge thanks.

podio api file upload from url

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

Facebook marketing api upload video to AdVideo

I'm new to FB marketing API.
I'm using php to create a function which handles the creation of the adVideo:
public function getUploadVideo() {
Api::init($this->appId, $this->appSecret,$this->token);
$video = new Advideo(null, 'act_' . $this->adAccountId);
$video->{AdVideoFields::SOURCE} = 'https://s3-us-west 2 .amazonaws.com /unittest-tvpage-com/testsuite/videos/big_buck_bunny.mp4';
$video->{AdVideoFields::NAME} = 'test_video';
$x = $video->create();
The video I'm using does not need any permissions and it can be directly downloaded.
When I run the function I get the following error message:
Type: FacebookAds\Exception\Exception
Code: 26
Message: couldn't open file "https://s3-us-west-2.amazonaws.com/unittest-tvpage-com/testsuite/videos/big_buck_bunny.mp4"
Any ideas why the file could not be opened?
Thanks
As per documentation:
https://developers.facebook.com/docs/marketing-api/reference/ad-account/advideos
To add the video using the url is file_url not source. The source parameter is used for uploading a file.

$_FILES to a resource - Laravel 5 and Dropbox

Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.
Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)
Here is my actual code for the update user (Update the user image, and get the link to the file).
$input = $_FILES['picture'];
$inputName = $input['name'];
$image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));
Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);
// $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);
return dd($image);
In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:
This is when I've used fopen() on a file stored on the public folder
http://i.imgur.com/07ZiZD5.png
And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.
http://i.imgur.com/pSv6l1k.png
Any Idea?
Try a simple fopen on the uploaded file:
$image = fopen($_FILES['picture']['tmp_name'], 'r');
https://www.php.net/manual/en/function.fopen.php
You don't need an image stream but just a filestream, which fopen provides.

Writing IPTC data to an image using iptcembed() in Codeigniter

I'm trying to write some IPTC data to an image within an upload form in Codeigniter.
I can get it to read out the data great, but I need to be able to write it too.
Basically when I try and write the data, I get this error:
Severity: Warning
Message: iptcembed() [function.iptcembed]: Unable to open
http://www.mydomain.com/photos/testimage1.jpg
Filename: controllers/upload.php
Line Number: 139
Trouble is, the URL is correct, I don't understand why it can't open the file. The file is uploaded before the iptcembed() is run to ensure that it can find the image.
Line 139 is:
$path = base_url()."photos/".$filename;
$filename is the filename of the file that is uploaded earlier in the function.
I'm using the first example from the PHP Manual to write the IPTC data.
Ideas?
Probably the solution has been found, but just to share.
My problem was the full url, probably in this case
"$path = base_url()."photos/".$filename;" the base_url is causing that troubles.

Categories