Ok all here is what i have
class album
{
var $user_id;
var $size_limit = 100000;
var $nb_limit;
var $stored_pictures;
function album($user_id, $size_limit, $nb_limit = 5)
{
$this->user_id = $user_id;
$this->nb_limit = $nb_limit;
$this->size_limit = $size_limit;
}
function display_album($username)
{
$q = "SELECT picture_id, name, size FROM picture WHERE username = '$username'";
$this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
if(mysql_num_rows($this->stored_pictures))
{
print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
while($d = mysql_fetch_row($this->stored_pictures))
{
print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td ></tr>\n";
}
print "</table>\n";
}
else
print "<p>No picture ! </p>\n";
}
function store_picture($username)
{
//$_FILE is a superglobal so you can get it from there
foreach ($_FILES as $file)
{
print "<p>".$file['name']."<br />";
print "temp :".$file['tmp_name']."<br />";
print "type :".$file['type'] ."<br />";
print "size :".$file['size'] ."<br />";
print "error :".$file['error'] ."</p>";
if($file['size'] >= $this->size_limit)
{
print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
return false;
}
if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
{
if(file_exists("pict/".$file['name']))
$file['name'] = $this->user_id.$file['name'];
$q = "INSERT INTO picture (picture_id, name, size, username) VALUES ('', '".$file['name']."', '".$file['size']."', '$username')";
mysql_query($q) or die(mysql_error()."<br />".$q);
}
else
{
print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
return false;
}
if(!is_dir("pict"))
mkdir ("pict", 0700);
copy($file['tmp_name'], "pict/".$file['name']);
}
}
function delete_picture()
{
$q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
$r = mysql_query($q) or die(mysql_error()."<br />".$q);
$d = mysql_fetch_row($r);
$file = "pict/".$d[0];
$q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
mysql_query($q) or die(mysql_error()."<br />".$q);
if(file_exists($file))
unlink($file);
}
function display_upload_form($nb_file = 1, $username)
{
$q = "SELECT * FROM picture WHERE username='$username'";
$this->stored_pictures = mysql_query($q) or die(mysql_error()."".$q);
if($this->nb_limit <= mysql_num_rows($this->stored_pictures))
{
print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
for($i = 0;$i < $nb_file;$i++)
print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
print "<input type=\"submit\" value=\"upload\" />\n";
echo "$this->stored_pictures<br>";
echo "$this->nb_limit";
}
else
print "<p>no more upload allowed!</p>";
}
}
$album = new album($username, 100000, 5);
if($_GET["del_pict_id"])
$album->delete_picture();
if($_GET["up"])
$album->store_picture($username);
$album->display_album($username);
$album->display_upload_form($nb_file = 1, $username);
Under the function display_upload_form the $this->stored_pictures is pulling out a Resource id #22 but it suppost be be counting the number of rows.. Can somebody please tell me why it is doing that..