Page 1 of 1

User Uploaded Logo Image

Posted: 2022-03-26 17:32
by rpierce
Hello,

I have been using some code from a forum discussion (linked here) viewtopic.php?f=8&t=3840&p=14613&hilit= ... 4da#p14613 between pböttcher and bruceholt on uploading a user logo. I have that part working. But there is an additional part to the code that places a default logo image if the user does not upload one of their own. I can't seem to get that part of the code working. So as usual, I'm reaching out for help from the forum. Which by the way, is the best tech forum on the web in my humble opinion. I would love to have this functionality in my app. Please help if you can.

When a user uploads a logo image I can get it to show in my report. But if they don't upload a logo image I cannot get the default image to show. there are screen shots below:
LOGO Printing
Capture.JPG
Capture.JPG (27.89 KiB) Viewed 1269 times
Default LOGO not printing:
Capture2.JPG
Capture2.JPG (27.33 KiB) Viewed 1269 times
Here is the code I have been using:

Code: Select all

<?php

$image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true));
$path="../images/";
echo '<img src="'.$path.$image.'" id="company_image" style="max-width: 100px;">';

/*var_dump($path);*/

/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

 
if(file_exists($image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true)))) {
$path="../images/";
echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; max-height: 50px; background-color: transparent">';
}
     else {
    $image = 'default.jpg';
}
/*var_dump($image);*/

?>

Re: User Uploaded Logo Image

Posted: 2022-03-26 19:40
by pbottcher
Hi,

try this:

Code: Select all

<?php
/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

 
$path="../images/";
if(!file_exists($image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true)))) {
    $image = 'default.jpg';
}
echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; max-height: 50px; background-color: transparent">';

?>

Re: User Uploaded Logo Image

Posted: 2022-03-26 22:33
by rpierce
Hello, and thank you for helping!

I made the changes you indicated and the default logo is appearing but so is the uploaded logo. When the modified code you provided is used alone, only the default logo is shown. Irrespective of weather the user has uploaded an image or not. If no user logo is uploaded, a place holder is shown. I have included screen shots below.

Code: Select all

<?php
/* -- *********** PLACE CLIENT LOGO INTO JHA ******* */

$image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true));
$path="../images/";
echo '<img src="'.$path.$image.'" id="company_image" style="max-width: 100px;">';

/*var_dump($path);*/

?>


<?php
/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

$path="../images/";
if(!file_exists($image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true)))) {
    $image = 'default.jpg';
}
echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; background-color: transparent">';



/*var_dump($image);*/

?>
**************************

This what is shown if the user uploads a logo image:
upload.JPG
upload.JPG (16.08 KiB) Viewed 1246 times
***************************

This is what is shown if the user does not upload an image:
no-upload.JPG
no-upload.JPG (15.6 KiB) Viewed 1246 times

Re: User Uploaded Logo Image

Posted: 2022-03-27 09:46
by pbottcher
Hi,

the new code was not meant to be additional, but to replace the old one.
Nevertheless there is something missing.

So try only this:

Code: Select all

<?php
/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

$path="../images/";
$image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true));
if(!file_exists($path.$image)) {
    $image = 'default.jpg';
}
echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; background-color: transparent">';

Re: User Uploaded Logo Image

Posted: 2022-03-27 18:59
by rpierce
Hi again pböttcher,

I had thought to try the code you supplied on it's own in my experimenting but then it only showed either the uploaded logo or the default logo but won't show the default logo if none is uploaded by the user. The same is true with the new code. If I delete the
"!" in the IF statement. then only the default logo appears irrespective of weather or not the user uploads an image.
*****************
This is what appears if no image is uploaded by the user
*****************
no-upload.JPG
no-upload.JPG (12.47 KiB) Viewed 1219 times
*****************
This is what appears if the user uploads a logo
*****************
upload.JPG
upload.JPG (12.27 KiB) Viewed 1219 times
*****************

Code: Select all

<?php
/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

$path="../images/";
$image=sqlValue("SELECT logo FROM " . get_sql_from('company', false, true));
if(!file_exists($path.$image)) {
    $image = 'default.jpg';
}
echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; background-color: transparent">';
?>

Re: User Uploaded Logo Image

Posted: 2022-03-28 17:02
by pbottcher
Hi again,

can you please try this:

Code: Select all

<?php
/* *********** PLACE DEFAULT LOGO IF NO CLIENT LOGO UPLOADED ******* */

$path="../images/";
$image=sqlValue("SELECT if(count(1),logo,'default.jpg') FROM " . get_sql_from('company', true, true));

echo '<img src="'.$path.$image.'"  id="company_image" style="max-width: 100px; background-color: transparent">';