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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kenandrews45
Forum Newbie
Posts: 1
Joined: Wed Jul 06, 2011 12:45 am

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

Post 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>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply