darkfreaks Posted April 6, 2010 Share Posted April 6, 2010 hey there can anyone tell me how i would modify my picture album class to include folders? i want users to be able to create folders and put pictures into them or select a picture and be able to put it in which ever folder. current album class: <? if($session->isUnlimited()){$pic_limit = $nb_limit = 150;} if($session->isFree()){$pic_limit = $nb_limit = 50;} if($session->isWebmaster()){$pic_limit = $nb_limit = 200;} if($session->isAdmin()){$pic_limit = $nb_limit = 200;} echo"<div align='center'><h2>To have a picture on your profile click on <b>Default<b></h2></div>"; echo "<div style='width:800; height:650; overflow:auto'>"; class album { var $user_id; var $size_limit = 1048576; var $nb_limit; var $stored_pictures; function album($user_id, $size_limit, $pic_limit) { $this->user_id = $user_id; $this->size_limit = $size_limit; $this->nb_limit = $pic_limit; } function display_album($username) { $q = "SELECT picture_id, name, size, username, comment FROM picture WHERE username = '$username'ORDER BY picture_id ASC"; $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q); $numpic = mysql_num_rows($this->stored_pictures); if(mysql_num_rows($this->stored_pictures)) { print "<table width='562' border=1 cellpadding='1' cellspacing='1'><tr align='center'> <td colspan='4'>You have $numpic out of $this->nb_limit pictures! </td> </tr><tr><td width='200' align=\"center\"><b>Name</b></td><td width='83' align=\"center\"><b>Size</b></td><td width='150' align=\"center\"><b>Picture</b></td><td width='111' align=\"center\"><b>Action</b></td></tr>\n"; while($d = mysql_fetch_array($this->stored_pictures)) { print "<tr><td align='center' valign='top'><b>Picture Name:</b><br>".$d['name']."<br><br><b>Picture Comment:</b><br>".$d['comment']."</td><td align=center valign='top'>".$d[2]."</td><td height='125' align=center valign='middle'><a href='picture.php?id=".$d['picture_id']."'><img src=\"http://pict.gothicgreenwire.com/".$d['name']."\" width='100' height='100' border='0'/></a></td>"; print "<td align=center valign='top'><p><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></p> <p>Main Picture<br> <a href=\"".$_SERVER["PHP_SELF"]."?mainpic=Default&id=".$d['picture_id']."\">Default</a> </p> </td ></tr> \n"; } print "</table> "; } else print "<p>No picture ! </p>\n"; } function store_picture($username, $comment) { //$_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("(jpg|gif|png)", $file['name'])) { if(file_exists("pict/$username-".$file['name'])) $file['name'] = $username.$file['name']; $q = "INSERT INTO picture (picture_id, name, size, username, comment, main) VALUES ('', '$username-".$file['name']."', '".$file['size']."', '$username', '$comment', '')"; 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/$username-".$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++) $numpic = mysql_num_rows($this->stored_pictures) +1; print "<p>1 megabyte Limit. Pictures accepted: jpg,gif,bmp,png<br>Picucture N°$numpic : <input type=\"file\" name=\"file".$i."\" size=\"45\" class='ggwarea'><br>Comment: <input name='comment' type='text' size='50' maxlength='255' class='ggwarea'></p>"; print "<input type=\"submit\" value=\"upload\" class='button' />\n"; } else print "<p>no more upload allowed!</p>"; } } $album = new album($username, 1048576, $pic_limit); if($_GET["mainpic"]) { $_GET['id']; $mainpic = $_GET["mainpic"]; $database->UpdatePictureMainFirst($username); $database->UpdatePictureMain($mainpic, 'id'); header("Location: editgood/defaultpic.php");} if($_GET["del_pict_id"]) { $album->delete_picture(); header("Location: editgood/deletepic.php");} if($_GET["up"]){ $album->store_picture($username, $comment); header("Location: editgood/uploadpic.php");} $album->display_album($username); $album->display_upload_form($nb_file = 1, $username); echo"</div>";}else{ echo" You must be Logged in";} ?> </p> Quote Link to comment https://forums.phpfreaks.com/topic/197712-class-help/ Share on other sites More sharing options...
oni-kun Posted April 6, 2010 Share Posted April 6, 2010 { if(file_exists("pict/$username-".$file['name'])) $file['name'] = $username.$file['name']; $q = "INSERT INTO picture (picture_id, name, size, username, comment, main) VALUES ('', '$username-".$file['name']."', '".$file['size']."', '$username', '$comment', '')"; mysql_query($q) or die(mysql_error()."<br />".$q); } You should add the argument within the parent function, and allow them to create an album name there, and define it within the query. Doesn't seem that hard. Quote Link to comment https://forums.phpfreaks.com/topic/197712-class-help/#findComment-1037594 Share on other sites More sharing options...
darkfreaks Posted April 6, 2010 Author Share Posted April 6, 2010 hoiw would i exactly go about it though? Quote Link to comment https://forums.phpfreaks.com/topic/197712-class-help/#findComment-1037601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.