Multiple rows in mysql

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 664
  • Loc: Conroe, Texas

Post 3+ Months Ago

demon1.jpg
temp :/tmp/phpcKIgal
type :image/pjpeg
size :4279
error :0


Warning: move_uploaded_file(pict/demon1.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpcKIgal' to 'pict/demon1.jpg' in /home/happykj/public_html/ggwnew/userpictures.php on line 131


still did not work
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

I'm sorry.

With your FTP client, Check your chmod, if know how.(properties of the parent folder)

both paths seem to be OK in the move_uploaded_file() anyway, I'm still searching.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 664
  • Loc: Conroe, Texas

Post 3+ Months Ago

if you are meaning this

owner -> read, write, execute
group -> read, execute
public ->read, execute

if not that then i dont know what you mean.
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1615

Post 3+ Months Ago

Yeah that's it. I uploaded a file ok. I did get some mysql errors though.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 664
  • Loc: Conroe, Texas

Post 3+ Months Ago

but the file is not there...
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 664
  • Loc: Conroe, Texas

Post 3+ Months Ago

PHP Code: [ Select ]
<?php 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()
 
    {
 
         $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
        $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()
 
    {
 
        //$_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, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
 
                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);  
 
           move_uploaded_file($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)
 
    {
 
        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";
 
        }
 
        else
 
            print "<p>no more upload allowed !</p>";
 
    }
 
}
 
/* MY OWN CONNEXION
 
$pass = '******';
 
$db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
 
mysql_select_db("test") or die(mysql_error());  */
 
 
 
//I forced 1 in first argument for user id=1 for my test
 
$album = new album(1, 100000, 3);
 
if($_GET["del_pict_id"])
 
    $album->delete_picture();
 
if($_GET["up"])
 
    $album->store_picture();
 
$album->display_album();
 
$album->display_upload_form($nb_file = 1); ?>
  1. <?php class album
  2.  
  3. {
  4.  
  5.     var $user_id;
  6.  
  7.     var $size_limit = 100000;
  8.  
  9.     var $nb_limit;
  10.  
  11.     var $stored_pictures;
  12.  
  13.     function album($user_id, $size_limit, $nb_limit = 5)
  14.  
  15.     {
  16.  
  17.         $this->user_id = $user_id;
  18.  
  19.         $this->nb_limit = $nb_limit;
  20.  
  21.         $this->size_limit = $size_limit;
  22.  
  23.     }
  24.  
  25.     function display_album()
  26.  
  27.     {
  28.  
  29.          $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  30.  
  31.         $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  32.  
  33.         if(mysql_num_rows($this->stored_pictures))
  34.  
  35.         {
  36.  
  37.             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";
  38.  
  39.             while($d = mysql_fetch_row($this->stored_pictures))
  40.  
  41.             {
  42.  
  43.                 print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  44.  
  45.                 print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  46.  
  47.             }
  48.  
  49.             print "</table>\n";
  50.  
  51.         }
  52.  
  53.         else
  54.  
  55.             print "<p>No picture ! </p>\n";
  56.  
  57.     }
  58.  
  59.     function store_picture()
  60.  
  61.     {
  62.  
  63.         //$_FILE is a superglobal so you can get it from there
  64.  
  65.         foreach ($_FILES as $file)
  66.  
  67.         {
  68.  
  69.              print "<p>".$file['name']."<br />";
  70.  
  71.             print "temp :".$file['tmp_name']."<br />";  
  72.  
  73.             print "type :".$file['type'] ."<br />";  
  74.  
  75.             print "size :".$file['size'] ."<br />";
  76.  
  77.             print "error :".$file['error'] ."</p>";
  78.  
  79.             if($file['size'] >= $this->size_limit)
  80.  
  81.             {
  82.  
  83.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
  84.  
  85.                 return false;
  86.  
  87.             }
  88.  
  89.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
  90.  
  91.             {
  92.  
  93.                 if(file_exists("pict/".$file['name']))
  94.  
  95.                     $file['name'] = $this->user_id.$file['name'];
  96.  
  97.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
  98.  
  99.                 mysql_query($q) or die(mysql_error()."<br />".$q);
  100.  
  101.             }
  102.  
  103.             else
  104.  
  105.             {
  106.  
  107.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
  108.  
  109.                 return false;
  110.  
  111.             }
  112.  
  113.             if(!is_dir("pict"))  
  114.  
  115.                 mkdir ("pict", 0700);  
  116.  
  117.            move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
  118.  
  119.         }                
  120.  
  121.     }
  122.  
  123.     function delete_picture()
  124.  
  125.     {
  126.  
  127.         $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  128.  
  129.         $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  130.  
  131.         $d = mysql_fetch_row($r);
  132.  
  133.         $file = "pict/".$d[0];
  134.  
  135.         $q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  136.  
  137.         mysql_query($q) or die(mysql_error()."<br />".$q);
  138.  
  139.         if(file_exists($file))
  140.  
  141.             unlink($file);  
  142.  
  143.     }
  144.  
  145.     function display_upload_form($nb_file = 1)
  146.  
  147.     {
  148.  
  149.         if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  150.  
  151.         {
  152.  
  153.             print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  154.  
  155.             for($i = 0;$i < $nb_file;$i++)
  156.  
  157.                  print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  158.  
  159.              print "<input type=\"submit\" value=\"upload\" />\n";
  160.  
  161.         }
  162.  
  163.         else
  164.  
  165.             print "<p>no more upload allowed !</p>";
  166.  
  167.     }
  168.  
  169. }
  170.  
  171. /* MY OWN CONNEXION
  172.  
  173. $pass = '******';
  174.  
  175. $db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
  176.  
  177. mysql_select_db("test") or die(mysql_error());  */
  178.  
  179.  
  180.  
  181. //I forced 1 in first argument for user id=1 for my test
  182.  
  183. $album = new album(1, 100000, 3);
  184.  
  185. if($_GET["del_pict_id"])
  186.  
  187.     $album->delete_picture();
  188.  
  189. if($_GET["up"])
  190.  
  191.     $album->store_picture();
  192.  
  193. $album->display_album();
  194.  
  195. $album->display_upload_form($nb_file = 1); ?>


Ok problemmm It works. BUT everybody can see other pictures and things.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi, is it your own code above?

You should keep the class définiyion but change this part :

PHP Code: [ Select ]
 
/* MY OWN CONNEXION  
 
$pass = '******';  
 
$db = mysql_connect('*****', '*****', $pass) or die (mysql_error());  
 
mysql_select_db("test") or die(mysql_error());  */  
 
 
 
//I forced 1 in first argument for user id=1 for my test  
 
$album = new album(1, 100000, 3);  
 
if($_GET["del_pict_id"])  
 
    $album->delete_picture();  
 
if($_GET["up"])  
 
    $album->store_picture();  
 
$album->display_album();  
 
$album->display_upload_form($nb_file = 1);
 
 
  1.  
  2. /* MY OWN CONNEXION  
  3.  
  4. $pass = '******';  
  5.  
  6. $db = mysql_connect('*****', '*****', $pass) or die (mysql_error());  
  7.  
  8. mysql_select_db("test") or die(mysql_error());  */  
  9.  
  10.  
  11.  
  12. //I forced 1 in first argument for user id=1 for my test  
  13.  
  14. $album = new album(1, 100000, 3);  
  15.  
  16. if($_GET["del_pict_id"])  
  17.  
  18.     $album->delete_picture();  
  19.  
  20. if($_GET["up"])  
  21.  
  22.     $album->store_picture();  
  23.  
  24. $album->display_album();  
  25.  
  26. $album->display_upload_form($nb_file = 1);
  27.  
  28.  


it is the procedural part, that makes run the stuff.

like I said before,

PHP Code: [ Select ]
 
$album = new album(1, 100000, 3);  
 
 
  1.  
  2. $album = new album(1, 100000, 3);  
  3.  
  4.  

see the first argument '1" is an arbitrary value that makes works as an example, but you should put instead the variable $username , you the one you use for all the other stuff and that you pass in the links, so that logged user manages his own pictures.
Otherwise with my example, all os done depending on my pseudo username "1".
you should put right here the real current user , something like that :
PHP Code: [ Select ]
 
$album = new album($username, 100000, 3);  
 
 
  1.  
  2. $album = new album($username, 100000, 3);  
  3.  
  4.  


By the way the second argument is for the max allowed size of the pictures, and the third is for the max pictured allowed to store for the user.

Post Information

  • Total Posts in this topic: 97 posts
  • Users browsing this forum: No registered users and 52 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.