Page 1 of 1

problem in upload file code, plz help..........

Posted: Wed Jul 06, 2011 1:01 am
by kenandrews45
<body>
<?php
if(isset($result))
{
echo '<ul>';
foreach($result as $message)
{
echo"<li>$message</li>";

}
echo '</ul>';
}
else
{
echo 'error';
}
?>
<form action="" method="post" enctype="multipart/form-data" id="uploadimage">
<p>
<label for="image">Upload image</label>

<input type="file" id="image" name="image" />
<input type="submit" name="upload" value="upload" id="upload"/>
</p>
<?php
if (isset($_POST['upload']))
{
print_r($_FILES);
$path='C:/uploadtest/';
//move_uploaded_file($_FILES['image']['tmp_name'], $destination.$_FILES['image']['name']);
require_once('C:/wamp/www/realeatate/classes/ps2/ps2_upload.php');
print("$path";
try
{
$upload= new ps2_upload($path);
$upload->move();
$result=$upload->getMessage();
print ("$result");
}
catch (Exception $e)
{
echo $e->getMessage();
}

}
?>

</form>
</body>
</html>
==========================================================
<?php
class ps2_upload
{
protected $_uploaded= array();
protected $_destination;
protected $_message=array();
protected $_permitted=array('image/gif' ,'image/jpeg','image/pjpeg','image/png');
protected $_max=5120000;
protected $_renamed=false;

public function __construct($path)
{
if(!is_dir($path)||(!is_writable($path)))
{
throw new Exeception("$path must be a valid and writable directory");
$this-> _destination= $path;
$this->_uploaded=$_FILES;

}
}
public function move()
{
$field=current($this->_uploaded);
$success=move_uploaded_file($field['tmp_name'],$this->_destination.$field['name']);

if($success)
{
$this->_message[]=$field['name'].'uploaded successfully';
}
else
{
$this->_message[]=$field['name'].'not uploded';
}

}
public function getMessage()
{
return $this->_message;

}
}

?>
</body>
</html>

Re: problem in upload file code, plz help..........

Posted: Wed Jul 06, 2011 2:39 am
by social_experiment
What's the problem that you are having with the code?
(Use the php code button to wrap your php code in)

There is no MAX_FILE_SIZE hidden input field in your form so users can upload any size file that is smaller than the maximum set in php.ini