SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Maryland
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Requiring an attachment: if (!empty...

    I'm working with a guestbook-with-photos script (lazarusgb) and I don't know how to make it require an attachment. I believe this is the relevant code:

    Code:
    if (!empty($this->user_img))
      {
          $this->image_file = trim($this->user_img);
       }
    All the other dialogue-box-error-popups are called by code like this:
    Code:
        return $this->db->gb_error($this->db->LANG['ErrorPost7']);
    so I tried
    Code:
    if (!empty($this->user_img))
      {
          return $this->db->gb_error($this->db->LANG['ErrorPost7']);
       }

    but it had no effect.

    How can I cause an error message when there is no attachment?

    Thanks.
    Eric

  2. #2
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, $this->user_img would have to be empty for you display an error, no?
    PHP Code:
    if(empty($this->user_img)){
      return 
    $this->db->gb_error($this->db->LANG['ErrorPost7']);


  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Maryland
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha, so !empty means NOT empty. Good to know. I tried it without the ! and nothing happened except that no entries posted, empty or not.

    I also tried it with both options
    PHP Code:
          if (!empty($this->user_img)){
             
    $this->image_file trim($this->user_img);
               
    if (empty(
    $this->user_img)){
        return 
    $this->db->gb_error($this->db->LANG['ErrorPost7']); 
            }
          } 
    and that didn't work, either.

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a bit hard to know what's going on with only the posted code to go on. However, see what this does:
    PHP Code:
    if (!empty($this->user_img)){ 
       
    $this->image_file trim($this->user_img);
    }
    else{ 
      print 
    "error: user_img is empty"


  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Maryland
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING.


    Here's the whole section having to do with the image verification:

    PHP Code:
          if (is_array($this->userfile) && $this->userfile['userfile']['tmp_name'] != 'none' && (strpos($this->userfile['userfile']['type'], 'image') === 0))
          {
             
    $extension = array('1' => 'gif','2' => 'jpg','3' => 'png''6' => 'bmp');
             if (
    $this->userfile['userfile']['size'] > $this->db->VARS['max_img_size'])
             {
                return 
    $this->db->gb_error($this->db->LANG['ErrorPost6']);
             }
             else
             {
                
    move_uploaded_file($this->userfile['userfile']['tmp_name'], $this->include_path.'/'.$GB_TMP.'/img-'.$the_time.'.tmp');
                
    $size GetImageSize("$this->include_path/$GB_TMP/img-$the_time.tmp");
                if (((
    $size[2] > 0) && ($size[2] < 4)) || ($size[2] == 6))
                {
                   
    $this->image_file "img-$the_time.".$extension[$size[2]];
                   
    $img = new gb_image();
                   
    $img->set_destdir("$this->include_path/$GB_UPLOAD");
                   
    $img->set_border_size($this->db->VARS['img_width'], $this->db->VARS['img_height']);
                   if (
    $type == 'preview')
                   {
                      
    rename("$this->include_path/$GB_TMP/img-$the_time.tmp""$this->include_path/$GB_TMP/$this->image_file");
                      
    chmod($this->include_path.'/'.$GB_TMP.'/'.$this->image_file0755);
                      
    $new_img_size $img->get_img_size_format($size[0], $size[1]);
                      
    $GB_UPLOAD $GB_TMP;
                      
    $row['p_filename'] = $this->image_file;
                      
    $row['width'] = $size[0];
                      
    $row['height'] = $size[1];
                      eval(
    "\$this->tmp_image = \"".$this->template->get_template('user_pic')."\";");
                   }
                   else
                   {
                      
    rename("$this->include_path/$GB_TMP/img-$the_time.tmp""$this->include_path/$GB_UPLOAD/$this->image_file");
                      
    chmod($this->include_path.'/'.$GB_UPLOAD.'/'.$this->image_file0755);
                      if (
    $this->db->VARS['thumbnail'] == 1)
                      {
                         
    $min_size 1024*$this->db->VARS['thumb_min_fsize'];
                         
    $img->set_min_filesize($min_size);
                         
    $img->set_prefix("t_");
                         
    $img->create_thumbnail("$this->include_path/$GB_UPLOAD/$this->image_file","$this->image_file");
                      }
                   }
                }
                else
                {
                   return 
    $this->db->gb_error($this->db->LANG['ErrorPost7']);
                }
             }
          }
          if (!empty(
    $this->user_img))
          {
             
    $this->image_file trim($this->user_img);
          } 

  6. #6
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, okay. You have to put your error message outside of the initial if condition, simply put:

    PHP Code:
    if (is_array($this->userfile) && $this->userfile['userfile']['tmp_name'] != 'none' && (strpos($this->userfile['userfile']['type'], 'image') === 0)){
    //process the image etc...
    }
    else{
    //your error message


  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Maryland
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait, where exactly do I put this? My error message, I think, is
    return $this->db->gb_error($this->db->LANG['ErrorPost7']);

    Where, relative to the long chunk of code I posted before, does that go? I tried sticking it at the end, and it didn't work, and I tried just using the else clause and it didn't work.

  8. #8
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The chunk of code you posted only executes when there is a (valid) image found in post (the first if condition is met) -- plus: judging from the code's indentation, you haven't posted all of it. In your code, look for an else on the same indentation level as the first if. If the else is there, put your error message in it, otherwise create it first.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •