PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label openerp. Show all posts
Showing posts with label openerp. Show all posts

Monday, October 10, 2022

[FIXED] why is this imagepng not working?

 October 10, 2022     gd, openerp, php     No comments   

Issue

image_small.php looks like this:

<?php
$id = (isset($_GET['im'])) ? $_GET['im'] : 0;

//fetch the image from database
$query='SELECT image_small FROM hr_employee WHERE id='.$id;
$result = pg_query($dbconn, $query) or die('Query failed: ' . pg_last_error());

$raw = pg_fetch_row ( $result ,0)
$img=$raw['image_small'];

header("Content-Type: image/png");

if( !file_exists($cachefile) ) {
    imagepng($img, $cachefile);
    imagedestroy($img);
}

$fp = fopen($cachefile, 'rb');
fpassthru($fp);
exit;
?>

I get the following error:

imagepng() expects parameter 1 to be resource, string given


Solution

The error is very explicit, imagepng expects a resource. To be simple, imagine a resource as an object from which you cant't know the class. In fact, GD is developped in C language, and PHP wraps all unknown C structures inside resources.

So, you need to ask GD to create this resource for you, before using gd-family functions. If you stored your image raw, you'll get it raw and will need to use imagecreatefromstring function.

$gdh = imagecreatefromstring($img);
imagepng($gdh, $cachefile);


Answered By - Alain Tiemblo
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, July 16, 2022

[FIXED] What is the difference between "warning" and "UserError" in odoo?

 July 16, 2022     odoo-8, openerp, python, warnings     No comments   

Issue

Warning:

warning = {
                    'title': _('Warning!'),
                    'message': _('Exists the discount limit'),
                }
            return {'warning': warning}

UserError

raise UserError(_('Exists the discount limit'))

What is the difference between Warning and UserError in odoo


Solution

To answer it in simple manner, both are same in odoo. Because if you check in odoo/exception.py refer odoo exception here

It clearly understood that it is referring Warning as UserError. odoo warning is deprecated in odoo v9 and v10 due to ambiguity or collision with python built-in.

To get the information about python warning refer python warning documentation.

So it is recommended to use odoo.exceptions.UserError instead of Warning



Answered By - Janarthanan Ramu
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing