SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Apr 25, 2006, 03:19 #1
- 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); }
Code:return $this->db->gb_error($this->db->LANG['ErrorPost7']);
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
-
Apr 25, 2006, 03:51 #2
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']);
}
-
Apr 25, 2006, 04:49 #3
- 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']);
}
}
-
Apr 25, 2006, 05:00 #4
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";
}
-
Apr 25, 2006, 05:30 #5
- 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_file, 0755);
$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_file, 0755);
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);
}
-
Apr 25, 2006, 06:00 #6
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
}
-
Apr 25, 2006, 06:56 #7
- 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.
-
Apr 25, 2006, 07:01 #8
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