Author Topic: Optional upload and default image  (Read 12645 times)

0 Members and 1 Guest are viewing this topic.

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Optional upload and default image
« on: February 27, 2008, 03:22:02 PM »
I'm using 4images as a classified script. Thanks to this forum and support everything is working great.

As you know. classifieds have several categories. For example I have a category for Personals, Auto, Merchandise, Services, etc, with sub categories. In some cases, uploading a picture for a category seems appropriate (i.e. Personals - men looking for women) while others don't (i.e. Services - baby sitting).

After much searching on the forum for a solution, I'm hoping someone has a suggestion or solution for the following.

As you know, the member_uploadform.html is the template used to upload an image. I also use the same form so members can provide a description of the item they are posting.

 I want to give the members the OPTION of uploading their own image OR if an image isn't really needed for the ad,  a default image is uploaded (i.e. a person wants to post an ad in the baby sitting category, provide a description of their service in member_uploadform.html, but not upload  an image - in this case, I would like a default image to be placed with this ad).  I can create this default image, but the problem I'm having is how to implement the option for member to upload their own image or if they do not upload, a default image is provided. Having it optional is important.

If someone has a solution for the above  it would be apprecaited.

I know I'm asking too much, but if it was possible to have it for some categories it was required that a member to upload while other categories it would be OPTIONAL for them to upload their own image or instead use the default image would be great.

Beggars can't be choosy so I'll take what I can get  :).

Thanks

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #1 on: February 27, 2008, 04:19:49 PM »
Upload to their own image ... I no get this ... you mean ... members upload category ? If so ... is here: http://www.4homepages.de/forum/index.php?topic=18564.0
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #2 on: February 27, 2008, 05:32:59 PM »
Thanks for the reply thuderstrike. I looked at that link already but not what I'm looking for.

Sorry for not explaining well. Let me try again.

Quote
I want to give the members the OPTION of uploading their own image OR if an image isn't really needed for the ad


In member_uploadform.html  the member cam browse and upload their own image. This is how it is  by default. What I want is a member to have the option to upload their own image (as it is by default) OR if they do not want to upload their own image a default image  is uploaded.

I hope I explained that well.

Thanks


Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #3 on: February 27, 2008, 05:50:14 PM »
And ... what is default image and where is 4images is get default image for FTP folder ?
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #4 on: February 27, 2008, 06:04:23 PM »
Quote
I can create this default image, but the problem I'm having is how to implement the option for member to upload their own image or if they do not upload, a default image is provided. Having it optional is important

I would create it myself. Probably use photo shop and create a logo image as the default image. Upload it to the appropriate folder for it to be used as the default image. Not sure what folder that would be, but obviously there has to be a default image on the server for 4images to fetch when needed.

Thanks

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #5 on: February 27, 2008, 06:43:58 PM »
In 4images, if media image or thumb image is no detect, this is default icon image: 404.gif in templates/your_template/icons folder.

In member.php file,

find:

Code: [Select]
if ((empty($HTTP_POST_FILES['media_file']['tmp_name']) || $HTTP_POST_FILES['media_file']['tmp_name'] == "none") && ($remote_media_file == "" || !check_remote_media($remote_media_file))) {
    $error = 1;
    $msg .= (($msg != "") ? "<br />" : "").$lang['image_file_required'];
  }

replace:

Code: [Select]
$valid = true;
if ((empty($HTTP_POST_FILES['media_file']['tmp_name']) || $HTTP_POST_FILES['media_file']['tmp_name'] == "none") && ($remote_media_file == "" || !check_remote_media($remote_media_file))) {
    $valid = false;
}

find:

Code: [Select]
// Upload Media file
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
      $new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
      if (!$new_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
        $uploaderror = 1;
      }
    } else {
      $new_name = $remote_media_file;
    }

replace:

Code: [Select]
// Upload Media file
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
      $new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
      if (!$new_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
        $uploaderror = 1;
      }

    } elseif ($valid == false) {
    $new_name = "";

    } else {
      $new_name = $remote_media_file;
    }

find:

Code: [Select]
// Uplad thumb file
    $new_thumb_name = "";
    if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
      $new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, get_basefile($new_name));
      if (!$new_thumb_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
        @unlink(MEDIA_TEMP_PATH."/".$new_name);
        $uploaderror = 1;
      }
    }
    elseif (check_remote_thumb($remote_thumb_file)) {
      $new_thumb_name = $remote_thumb_file;
    }

replace:

Code: [Select]
// Uplad thumb file
    $new_thumb_name = "";
    if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
      $new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, get_basefile($new_name));
      if (!$new_thumb_name) {
        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
        @unlink(MEDIA_TEMP_PATH."/".$new_name);
        $uploaderror = 1;
      }
    }
    elseif (check_remote_thumb($remote_thumb_file)) {
      $new_thumb_name = $remote_thumb_file;

    } elseif ($valid == false) {
      $new_thumb_name = "";
    }

find:

Code: [Select]
if ($do_create) {

replace:

Code: [Select]
if ($do_create && $valid) {

find:

Code: [Select]
"file_name" => $new_name,

replace:

Code: [Select]
"file_name" => (isset($new_name) && isset($valid) && $valid) ? $new_name : ICON_PATH . "/404.gif",

find:

Code: [Select]
$file_extension = get_file_extension($new_name);

add before:

Code: [Select]
if ($valid) {

find:

Code: [Select]
$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";

add after:

Code: [Select]
} else {
      $file = ICON_PATH . "/404.gif";
      $media_icon = "<img src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" />";
      $site_template->register_vars(array(
        "media_src" => $file,
        "media_icon" => $media_icon,
        "image_name" => format_text(stripslashes($image_name)),
        "width_height" => $width_height
      ));
      $media = $site_template->parse_template("media/gif");
      $content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";
}
« Last Edit: February 27, 2008, 08:26:54 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #6 on: February 27, 2008, 06:51:50 PM »
Man, thuderstrike.........you are great..........haven't had a chance to test it, but I'm so thrilled with your tech support and quick response I had to let you know. After I make changes and test I will let you know if all worked (i expect it will).

Thanks for great support.


Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #7 on: February 27, 2008, 06:56:25 PM »
OOPS

After I made the changes I tested. Went to upload page and left the upload field blank. When I submit it goes to a new page and I got this error.

Template Error: Couldn't open Template ./templates/stylish_green/media/.html

Even though I got the above error, I notice the 404.gif still in the admin section waiting to be validated.

Hmmmm, how to eliminate the above error message and redirect back to home page.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #8 on: February 27, 2008, 07:33:26 PM »
I post patch. Try now (fresh upload).
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #9 on: February 27, 2008, 08:14:51 PM »
Sorry thunderstrike but still get error.

Template Error: Couldn't open Template ./templates/stylish_green/media/gif.html.html


I started fresh, cleared cache, even did the changes twice to be sure I did it correctly but still get error. After I submit, it goes to a new page and gives the above error. However,  the gif is in the ACP waiting for admin validation.






Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #10 on: February 27, 2008, 08:26:40 PM »
Right.

After all change - replace:

Code: [Select]
$media = $site_template->parse_template("media/gif.html");

for:

Code: [Select]
$media = $site_template->parse_template("media/gif");

;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline bigwillhere

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Optional upload and default image
« Reply #11 on: February 27, 2008, 09:21:30 PM »
still error


Template Error: Couldn't open Template ./templates/stylish_green/media/gif.html.html


Well friend, I don't want you to keep at it. If you want to give up, I understand. I guess it is one of those things that isn't changeable.

thanks for your time and support. I appreciate it.



Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: Optional upload and default image
« Reply #12 on: February 28, 2008, 03:09:38 AM »
Is no possible after this change for see same error. Check if file is save before upload to server. parse_template method is code with template extension in constructor. Is no possible for get same error after fix.
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline nameless

  • Full Member
  • ***
  • Posts: 147
    • View Profile
Re: Optional upload and default image
« Reply #13 on: March 21, 2010, 11:08:10 PM »
hi
thanks thunderstrike
i made if but i have a problem

i make the default image when no image upload 400 X 400 Pixel and this is ok but the problem with the thumbnail it came with the same size 400 X 400

i hope u understand me