Gossamer Forum
Home : Products : DBMan : Installation :

using image field with default image

Quote Reply
using image field with default image
I tried this (found in alternate image post 1167) and when I try to access the add/view/delete/modify... I get the popup box that says I've started to download a file!

Here's what I put and where:

# Full path and file name of the html routines.
require $db_script_path . "/html.pl";
# Full path and file name of the default photo.
$default_photo = "http://www.amix.com/homefinder/fsbos/photos/default.jpg";
$photo_path = "/opt2/amix/httpd/htdocs/homefinder/fsbos/photos"; #no trailing slash!
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="http://www.amix.com/homefinder/fsbos/photos/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}

What goes in the add/search forms to have this field to search for the uploaded file and if it's not available insert the default image?
Quote Reply
Re: using image field with default image In reply to
The syntax error could be caused by not closing off a previous print statement. (I do it all the time! Smile )

Your subroutine should look like this:

Code:
<td>|;
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="$photo_url/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}
print qq|</td>

If you have it that way, then I'll need to look at your html.pl file to be able to tell you what's wrong.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
I'm assuming this is all in your default.cfg file.

Take out

if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="http://www.amix.com/homefinder/fsbos/photos/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}

Add the following to default.cfg:

$photo_url = "http://www.amix.com/homefinder/fsbos/photos";

In html_record (html.pl file), in the place where you want to show the image, use

Code:
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="$photo_url/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}

I think the reason you're getting a message to download the file is that you have the print statements in default.cfg.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
Ok, I corrected the code in default.cfg:
$photo_url = "http://www.amix.com/homefinder/fsbos/photos";

and put this in between the <td></td> on the sub html_record:
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="$photo_url/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}

and I'm getting this:
syntax error at ./html.pl line 227, near ">|"
syntax error at ./html.pl line 229, near "else"


------------------
Quote Reply
Re: using image field with default image In reply to
Help!!
The ID key count is still not working. I checked the default.count file and it had all the userid's in it rather than a #, so I deleted everything, changed the .count file to 0 and added a new test. default.count file now shows 'johndoe'.

For the Price field the $ appears automatically (ok). I've tried using the commify line (doesn't add the comma) and commenting it out and entering the number with a comma - either way it puts a ">" at the end of the number.

I'd like to have hyperlinks for these fields but they aren't working (yet!): VTour, Open House, URL and Email. I've got the ttp:// showing up in the URL field ok, but the field does not link in the display.

For the VTour and Open House fields - I'm hoping to follow your thought from the file upload mod...ie have the user enter their ID (1234.html) for each field to link to their listings in the other directories.

Sure wish I could send you a cold 6-pack or something! You're probably as frustrated as I am having to hear from me again. Any suggestions will be greatly appreciated! In case it will help, I've saved the files as .txt files at http://www.amix.com/dbman/ .
Quote Reply
Re: using image field with default image In reply to
The problem with your ID field is that you have $auth_user_field = 0;. Field 0 is your counter field. Since you don't want users to be able to only view or modify/delete their own records, set the $auth_user_field to -1.

I know the "commify" line works. It won't do you any good (and you don't want to have it) in either of your form subroutines. This is only for sub html_record. This may be why you're having other problems, too.

If you want to have a link, you need to make one:

Code:
<a href="$rec{'URL'}">$rec{'URL'}</a>
<a href="mailto:$rec{'Email'}">$rec{'Email'}</a>

You have the link there, but no text to create the clickable part.

If you have the users use their ID for a webpage, that's fine, but you can only have them use it for one URL. (Can't have two files with the same name. Smile )

My normal drink is Earl Grey tea -- and a lot of Pepsi's! Smile

------------------
JPD







[This message has been edited by JPDeni (edited August 15, 1999).]
Quote Reply
Re: using image field with default image In reply to
On the ID field - I DO want users to be able to view everything but only modify/delete their own records....So should I be adding a 'username' field and using that field number for the $auth_user_field? Otherwise how does the script know whose record it is to allow modifying the record?

Another duh from me on the url/email links. So sorry to waste your time on that one.

I'll try the commify line again once I get this other stuff working.

And I'm trying to follow not being able to have two files with the same name - since the files would be in different directories won't that work?
Quote Reply
Re: using image field with default image In reply to
I'm getting more confused - they enter a username to login, right? And the record the add is associated with that username to allow them to modify/delete their records, right? So does setting $auth_user_field to -1 make that work? And therefore I don't need to add a userid field? I think my brain stopped working about noon today Smile
Quote Reply
Re: using image field with default image In reply to
I'm getting this message now when I tried to add a listing:
CGI ERROR
Error Message: Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: Can't find string terminator "|" anywhere before EOF at ./html.pl line 475.
(I reposted the txt file if that helps)
Line 475 is in the sub html_view_search. I'm not seeing anything missing.
Quote Reply
Re: using image field with default image In reply to
I guess forget the last post - not sure why, but it worked this time!

It's still not loading the default.jpg photo and it's still putting a ">" at the end of the price. aaaagggggghhhhhhh.

Quote Reply
Re: using image field with default image In reply to
 
Code:
$default_photo = "http://www.amix.com/homefinder/fsbos/photos/default.jpg";

That was correct. Just like on an html page, you need to have the URL of the image in order to print it out.

I'm not sure why you changed it to the path in your .cfg file. Change it back.

Quote:
it's still putting a ">" at the end of the
price

That's because you have an extra ">" after the price. Below is from your html.pl file:

<TR><TD valign=top><$font>$rec{'Price'}><BR>

It should be

<TR><TD valign=top><$font>$rec{'Price'}<BR>



------------------
JPD





Quote Reply
Re: using image field with default image In reply to
For some reason, the thing that's coming up on your pages is

<img src="http://www.amix.com/homefinder/fsbos/open/">

Do you know where that's coming from?


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
I changed what was making <img src="http://www.amix.com/homefinder/fsbos/open/"> show up in the source, but now it's showing 1.jpg (which doesn't exist) and not putting in the default.jpg. I thought it would search for 1.jpg and when it wasn't found it would display default.jpg. Is that what it's supposed to do?
Quote Reply
Re: using image field with default image In reply to
Everything working except the default photo - it still shows the broken image.

default.cfg has:
# Default photo directory.
$photo_url = "http://www.amix.com/homefinder/fsbos/photos";
# Default photo file.
$default_photo = "http://www.amix.com/homefinder/fsbos/photos/default.jpg";

html.pl has:
<td valign=middle>|;
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="$photo_url/$rec{'photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}
print qq|</TD></TR>
Quote Reply
Re: using image field with default image In reply to
I looked at your default.cfg file, and I couldn't find the variable $photo_path. Did I miss it?

In order to check for the existence of a file, you have to follow the path to the file. In order to display the graphic, you have to use the URL of the graphic.

Another problem I see in your html.pl file is

Code:
if (-e "$photo_path/$rec{'photo'}") {
print qq|<img src="$photo_url/$rec{'Photo'}">|;
}

Your .cfg file has

Code:
Photo => [10, 'alpha', 30, 50, 0, '', ''],

So, you must use

Code:
if (-e "$photo_path/$rec{'Photo'}") {
print qq|<img src="$photo_url/$rec{'Photo'}">|;
}

But that doesn't explain why the script is printing out a non-existent file.

However, since you have a field for the Photo filename, it might be better to delete the file information from files without a Photo and try

Code:
if ($rec{'Photo'}) {
print qq|<img src="$photo_url/$rec{'Photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}
print qq|</TD></TR>

Then you can dispense with the path to the file.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
I tried changing the $rec{'photo'} to 'Photo" and added $photo_path = "/opt2/amix/httpd/htdocs/homefinder/fsbos/photos"; in default.cfg and it still gave the broken image. So I took out the $photo_path and put this in html.pl:
<td valign=middle>|;
if ($rec{'Photo'}") {
print qq|<img src="$photo_url/$rec{'Photo'}">|;
}
else {
print qq|<img src="$default_photo">|;
}
print qq|</TD></TR>

It still shows the broken image with 7.jpg (which doesn't exist) in the page source. So I added another test entering default.jpg - that way it doesn't show the broken image.

If I'm going to use the file-upload mod so users can upload their photo, should I just skip this and start reading through that? Did I ask before if there's a way they can fill out the add form and upload 1.jpg and then go back to the add form and upload 1a.jpg, 1b.jpg, 1c.jpg etc to be able to upload more than one photo?
Quote Reply
Re: using image field with default image In reply to
If you are keeping the Photo field in your database, you could just have the default.jpg as a default value for the field. Then you wouldn't have to mess with any "if - else" statements at all.

I think you did ask about multiple uploads. (At least somebody did recently.) I don't know enough about how the script works to be able to tell you how to do that. I did have a little bit of an idea, but it didn't work.

I have just ordered a book on the module that allows for uploads. It's a special order book and they say that it may take as long as two weeks to get here. I may be able to give you some more info after I have a reference that tells me what the heck is going on with that script!


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
Just to make sure I'm following - if I use the file-upload mod I can just have $default_photo = "default.jpg" in the .cfg file and it will look for the uploaded photo and if it's not there display default.jpg? And that way I don't need the Photo field?

I'm still reading the mod - it looks like they can upload the photo from html_add_success or html_modify_form_record. Where it has <input type="file" name="file-to-upload-01"...> couldn't there be additional fields for file-to-upload-02, 03, 04...? And have it re-name them ID#.jpg, ID#a.jpg, ID#b.jpg etc?
Quote Reply
Re: using image field with default image In reply to
 
Quote:
if I use the file-upload mod I can just have
$default_photo = "default.jpg" in the .cfg file and it will look for the uploaded photo and if it's not there display default.jpg? And that way I don't need the Photo field?

Technically, yes. But I wouldn't try it with the file-upload mod until you got the same syntax to work using a field.

Quote:
'm still reading the mod - it looks like they can upload the photo from html_add_success or html_modify_form_record.

That is correct.

Quote:
Where it has <input type="file"
name="file-to-upload-01"...> couldn't there be additional fields for file-to-upload-02, 03, 04...? And have it re-name them ID#.jpg, ID#a.jpg, ID#b.jpg etc?

Possibly. If you want to try it, go ahead. I don't think I'll be able to help much if you have problems, since I don't feel confident enough with the script. But if you want to give it a shot, I'll stand by the sidelines and cheer.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
YOU'LL be on the sidelines doing the cheering??!! Sounds like I better not try it!

What do I need to do to get the default image thing to work with the Photo field?
Quote Reply
Re: using image field with default image In reply to
I don't know. It seems that your code was correct.

You might try putting back the

if (-e "....

syntax, but this time don't use a variable. Just put the path to the file in there.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
Isn't this what I had before??!! Oh well, it's working now! I'm seeing default.jpg's all over the place......yipppeeeeeee!
<td valign=middle align=right>|;
if (-e "$photo_path/$rec{'Photo'}") {
print qq|<img src="$photo_url/$rec{'Photo'}">|;
}
else {

How do you do this?! You're incredible!
print qq|<img src="$default_photo">|;
}
print qq|</TD></TR>
print qq|
Quote Reply
Re: using image field with default image In reply to
 Smile Looks like this time it eventually did.

Now that you know your images will work, you can try the file-upload mod -- but with only one file at the present time. Still, it's best to go with small steps.


------------------
JPD





Quote Reply
Re: using image field with default image In reply to
I was so excited to see default.jpg's I rewarded myself by re-reading the file-upload mod a second time! I'll be trying that next and if we can't come up with a way to upload more than one, I figure there's always email Smile

Thanks LOADS for all your help! You have the patience of a gazillion saints Smile