Batch creative image update with ADS Api? - batch-file

I try to update ads group with batch request. Everything is going fine if not add image_file param but when add it return an error.
My ad_specs;
Array
(
[method] => post
[relative_url] => 6003452316521?name=ReklamGrubu915&max_bid=50&bid_type=1&targeting={"gender":["1","2"],"age_min":"30","age_max":"40","countries":["TR"],"keywords":["#Nike, Inc."],"cities":[{"name":"Istanbul"},{"name":"Ankara"},{"name":"Izmir"}]}&creative={"title":"Ev Yemekleri","body":"Evde harika lezzetler!","link_url":"http://www.xxxxx.com/dealer.php?kat=334","image_file":"img17.jpg"}
)
And also add image to batch_params
$batch_params['img17.jpg'] = '/var/www/images/img17.jpg'
i send it but its return this error;
Error 1487242 - Image Resize Failed - the getimagesize function returned false
If i remove image_file param every update is going fine so batch request true. Image file exist in right directory. i try to change image_file params to 'attached_files'. Then there is no errors looking everything went right, return data is true but i see facebook ads manage page there is no image change?
Any ideas ? May its a bug please help ? I am using PHP SDK.

When you specify the file name of image in your creative, you have to add the image file as multi-part MIME POST. You are currently giving the image path. ($batch_params['img17.jpg'] = '/var/www/images/img17.jpg'). Effectively you need to upload the image to facebook with request.
Alternatively, you can first create a image in library using Fb Ad Image Api and then use the image_hash in creative.
$image = new AdImage(null, 'act_<ACCOUNT_ID>');
$image->{AdImageFields::FILENAME} = '<IMAGE_PATH>';
$image->create();
echo 'Image Hash: '.$image->{AdImageFields::HASH}.PHP_EOL;
and then
$creative = new AdCreative(null, 'act_<ACCOUNT_ID>');
$creative->setData(array(
AdCreativeFields::TITLE => 'My Test Creative',
AdCreativeFields::BODY => 'My Test Ad Creative Body',
AdCreativeFields::OBJECT_URL => 'https://www.facebook.com/facebook',
AdCreativeFields::IMAGE_HASH => '<IMAGE_HASH>',
));

Related

My new Discord.Attachment() is not working It is showing an error in my discord.js bot

} else if (msg.content === '?_saifz test') {
const attachment = new Discord.Attachment('https://th.bing.com/th/id/OIP.CK95Aog4xZCaWVHnAr61pwHaHa?w=183&h=183&c=7&o=5&dpr=1.25&pid=1.7') // the problem
msg.channel.send(attachment)
}
})
keepAlive()
client.login(process.env.lolUCannotGetToken)
I didn't put the other command because they work.
That is not a valid image file type. You'll need to find a link to an image with a valid extension such as .jpg, .png or .jpeg.
Also, in order to prevent issues with the site taking the image down from their servers, I suggest you download the image to your project, so it's there forever.

How to Disable Direct file Download via .htaccess

I want to disable direct file download to my .zip files.
If my website is the referrer then only download the file.
I am using Apache server
You can try this one which will help you but I will suggest you to research more on this.However you can put the below code for the work.
Also make changes to the below code for the changes.
<?php
// This is to check if the request is coming from a specific domain domain.com
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] !== 'domain.com') {
// Output string and stop execution
die("Hotlinking not permitted");
}
echo "Executing code here";
?>
You need to change your domain above eg. clubapk.com instead of domain.com

Laravel returning a 404 on an image

This should be fairly simple though it is completely stumping me.
I have a backend Laravel installation running on localhost:8000
I have a front end Angular app running on localhost:9001.
I have some 'static' images I have included in my seed data (eg.
'1', 'user.png'), these images are being rendered perfectly in my front end (they are also served from the exact place my image uploads are going).
The URL I am currently serving images from is http://localhost:8000/images/{filename}
I can upload images from the front to the back end and they appear in the DB and the image is being put in the filesystem, I'm populating the correct URL in my front end (as evidenced by the previous URL).
My uploaded images are not being shown.
In my logs I am getting:
[2015-01-20 18:13:49] local.ERROR: NotFoundHttpException Route: http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg [] []
[2015-01-20 18:13:49] local.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'
I tried a method in my routes file, but couldnt see why, when I am already serving some images already?
I have also set all permissions to 755 on my /images folder.
Any ideas?
I'm not sure I follow every bit of multi-system interaction you have going on, but I'd drop back to first HTTP principles.
Try accessing the image URL directly.
http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
If the error in your browser (or your logs, if you're not developing with debug set to true) is
local.ERROR: NotFoundHttpException Route: http://localhost:8000/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
This means your web server couldn't find a file at images/j249ae747ce28c317e02f1fb6d0a10c3.jpg, and handed the request to Laravel. This means you need to figure out why your webserver can't see the file.
Assuming you're serving index.php from the public folder
Do you have a public/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg file?
Are you sure? Copy and paste the path into terminal and to a ls public/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg to make sure your brain isn't missing some subtle case issue
Are any errors showing up in your web server's logs (not Laravel's)
Can you create a text/html file in the images folder and serve it? If not, then you may not be pointing your web server at the folder you think you are.
Something like
http://localhost:8000/images/test.txt
http://localhost:8000/images/test.html
Some first principles debugging like that should point you in the right direction.
rm public/storage
php artisan optimize:clear
php artisan storage:link
This worked for me.
The problem is you haven't generated a url for your uploaded image
Try accessing your url like this
http://localhost:8000/storage/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
To generate the above url
Add this method \Storage::disk('public')->url(); method in your controller.This method accesses the public disk array which is found in Config\filesystems.php and it generates a url in the following format
http://localhost:8000/storage/images/j249ae747ce28c317e02f1fb6d0a10c3.jpg
For example the method below stores the image in the image folder and generates the url of the image path.
public function uploadImage(Request $request)
{
$request->validate(['image'=>'file|image|max:5000']);
$imageProfile = new ImageProfile();
if($request->hasFile('image') && $request->file('image')->isValid())
{
$image = $request->file('image')->store('images');
$imageProfile->image_profile_url = \Storage::disk('public')->url($image);
$imageProfile->save()
}
return response()->json($imageProfile,200);
}
The code returns a Json response below
{
"id": 13,
"image_profile_url ": "http://127.0.0.1:8000/storage/images/cxlogqdI8aodERsmw74nmEx7BkxkWrnyJLMH7sFj.jpeg",
"updated_at": "2020-01-13 16:27:37",
"created_at": "2020-01-13 16:27:37",
}
Try to copy the url and test it in postman.
Visit the link to learn more about Laravel file storage
Laravel File Storage
Hope it helps.
laravel 8
Controler function
public function store(Request $request)
{
$this->validate($request, [
'site_title' => 'required',
'logo_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$input['logo_image'] = time().'.'.$request->logo_image->getClientOriginalExtension();
$request->logo_image->move(public_path('images'), $input['logo_image']);
$input['site_title'] = $request->site_title;
//dd($input);
Site_settings::create($input);
return back()->with('success','Image Uploaded successfully.');
}
blade view
<td>
<img src="{{ url('/images/').'/'.$site_settings->logo_image ?? '' }}" alt="" width="250px" height="auto">
</td>

CakePHP Upload Plugin: Programmatic File Retrieval without a Form

I use CakePHP-Upload plugin, now need to use the upload without form, following this example: Programmatic File Retrieval without a Form
All my upload are stored in the associated model, called the Attachment.
So when I save the article, at the same time save the images in Attachmen model.
Plugin documentation suggests something like this:
<?php
$this->Article->set(array('file' => $image_path)); // ?????
$this->Article->save();
?>
I have a larger collection of images on the server, previously uploaded via the Joomla CMS, now I have a migration of data to a custom CMS built on CakePHP framework. I need to take all these pictures and upload again, through this plugin.
How to properly use this plugin for my needs, I try to put the path to a local picture, but uploading is not working ???
EDIT
$image_path = WWW_ROOT . 'img' . DS . 'attachment' . DS . '59'.DS.'hpim4799.jpg';
debug($image_path);
'C:\xampp\htdocs\portal\webroot\img\attachment\59\hpim4799.jpg'
Do not save the record and not create new images.
Note, uploading through HTML form works well, I use windows 7 and xampp server.
EDIT 2 / Solution
Image path must be valid url like 'http://localhost/portal/img/attachment/59/hpim4799.jpg'
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
Thank you.
Can you tell me what the content of the variable $image_url is? The doucmentation says you can add a file via the form, or you can do it programmatically. If you do that, use the $image_url as path to the image. If you got an associated model like Attachment you shoud use:
<?php
$this->Article->set(array('Attachment.file' => $image_path)); // path + file to file
$this->Article->save();
?>
After hours of searching for solutions and detailed inspection of the Behavior code I finally found it.
Because Behavior uses php FILTER_VALIDATE_URL Filter, path must be a valid URL. Here is an example:
<?php
$image_path = Router::url('/', true) . 'img/attachment/59/hpim4799.jpg';
// return http://localhost/portal/img/attachment/59/hpim4799.jpg
$this->Article->Attachment->set(array('file' => $image_path));
$this->Article->Attachment->save();
?>

Integrating a file browser into ckeditor & CakePHP

recently found an article in http://hashtwo.com/blog/integrating-a-file-browser-into-ckeditor-cakephp to integrate a file browser into ckeditor (file manager of core five labs )
I followed the steps but i get an error when I click the browse server button,
Missing Controller:
Error: CkeditorController could not be found.
I had the same error at some point during my setup, but I don't seem to recall what was it and how I fixed it. Let me know if my next solution does not fix your problem and I will investigate a little more:
First I followed the following tutorial which worked well, but missed the Authentication part: http://labs.corefive.com/projects/filemanager/
Then I used the tutorial you referenced, except for the last section of code provided. Instead I added the following code directly to my view page: admin_add.ctp
<?php echo $form->textarea('body', array(/*'class'=>'ckeditor', */'id' => 'body', 'class' => 'body')) ?>
<?php
include_once 'ckeditor/ckeditor.php' ;
//require_once 'ckfinder/ckfinder.php' ;
//$initialValue = 'Default value goes here' ;
$ckeditor = new CKEditor() ;
$ckeditor->basePath = '/ckeditor/' ;
$ckeditor->config['filebrowserBrowseUrl'] = '/ckeditor/filemanager/index.html';
$ckeditor->config['filebrowserUploadUrl'] = '/ckeditor/filemanager/connectors/php/filemanager.php';
$ckeditor->config['filebrowserImageBrowseUrl'] = '/ckeditor/filemanager/index.html?type=Images';
$ckeditor->config['filebrowserImageUploadUrl'] = '/ckeditor/filemanager/connectors/php/filemanager.php?command=QuickUpload&type;=Images';
$ckeditor->config['filebrowserWindowWidth'] = '800';
//CKFinder::SetupCKEditor( $ckeditor,'/ckfinder/' ) ;
// This will replace CakePHP textarea listed above.
$ckeditor->replace('body');
?>
Also, for the Auth Section of his tutorial I changed it to match my requirements:
function auth() {
session_name("CAKEPHP");
session_start();
if(isset($_SESSION['Auth']['User']) )
{
//Since CKEditor for me is only used in the admin section
//I make sure only admins can access it, group_id=1
if($_SESSION['Auth']['User']['group_id'] == 1)
{
return true;
}
}
return false;
}
If it tries to find a controller this means it can not access the editors file or folder and instead the dispatcher of CakePHP gets the request and tries to load a fckeditor controller.
This means you'll need to place the editor in the right directory (for example app/webroot/fckedtor/) or use the correct url to access it.

Resources