10-01-2008, 12:44 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Oct 2008
Posts: 18
Thanks: 0
|
how to capture and show error in oop php to user?
hi, i am new to oop php programming style.. i am trying to write a image class to process images, but how do i capture the error(for example when you upload a non image file) and show it to the user?
PHP Code:
my image class
----------------------------------------------------
<?php
class image
{
private $allowextension = array("image/gif","image/jpeg","image/png");
private $source;
function __construct($source)
{
$this->source = unserialize($source);
//check whether the upload file is the extension that is allow
if(!in_array(($this->source['type']), $this->allowextension))
{
#how do i show an error to the user?.. in a presentable way
return false;
}
}
}
?>
PHP Code:
my form
---------------------------------------------------
<?php
include("imageClass.php");
if(isset($_FILES["file"]) && !empty($_FILES["file"]))
{
$upload = serialize($_FILES["file"]);
$image = new image("$upload");
}
else
{?>
<form method="post" enctype="multipart/form-data" action="<?php echo
$_SERVER['PHP_SELF']; ?>" >
<input type="file" name="file" /><input type="submit" value="Upload"/>
</form>
<?php } ?>
I am looking at try and catch but couldn't understand how to show it to the user in a more customizable way(can be use with css).
Thanks in advance!
Last edited by kokjj87 : 10-01-2008 at 01:58 PM.
|
|
|
|