PDA

View Full Version : Need Help / Example


ptmuldoon
02-22-2005, 07:05 PM
Hi, I have a few books and tutorials that I'm reading and trying to learn php with, and have some code that I would like to try and alter a little bit.

Basicially, my understanding of the code is that it looks for a user to include an image to upload, and if one is not provided to give an error message. I want to alter that so that if a user does not provide an image, that it will use a default.gif image on the site/webhost.

The code places the user upload images into an images/articles/X/ folder, where X is a number for each article submitted. Thus, a new folder is always created for each new submission, where the images are placed.

I figured I would place the default image as /images/articles/default.gif. So, if the user didn't supply the image, the script would look there and get that image.

The code I'm looking at looks like this, and I think I need to add an elseif command somplace towards the top, but I haven't learned enough to figure this out yet.

If anyone can help, I'd be very grateful.

$path = $path.'/';
if (is_uploaded_file($icon['tmp_name']))
{
if (file_exists("$path" . $icon['name']))
{
eval(print_standard_error('vbart_filealreadyexists'));
}

$result = copy($icon['tmp_name'], "$path" . $icon['name']);
if (!$result)
{
$error = ob_get_contents();
eval(print_standard_error('vbart_errorwriting'));
}

$newpath = $vbart_options['vbartartimgpathab'].$artid."/";
$iconpath = $newpath.$icon['name'];
echo '<p>'.$vbphrase['vbart_imguploadsuccess'].'</p>';
$DB_site->query("UPDATE " . TABLE_PREFIX . "articles_article SET icon='$iconpath' WHERE articles_articleid='$artid'");
}
else
{
eval(print_standard_error('vbart_invalidfile'));
}

marek_mar
02-22-2005, 09:47 PM
This isn't the full code...

Why do you eval() functions? Why to you fetch the contents of the uotput buffer and do nothing with that var?