Multiple rows in mysql

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

Post 3+ Months Ago

Unknown column 'admin' in 'where clause'
SELECT picture_id, name, size FROM picture WHERE user_id=admin

that is what it gives me

and also i made it were when you sign up it collects your first and last name

how would i go about making it where a user can search for sombody by there first and last name the database field forthat is firstname, lastname, and username
  • 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

OK,

the error is because you changed the field as a string field so the query have to be changed (you have to add simple quote) :
$q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;

and add simple quotes :

$q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";

think about adding simple quotes in the insert query in store_picture() function.

For other kind of research
you will have to do a join query.

In the simplest way, Maybe you'll have to add functions in the class like that :
get pictures_by_first_name($first_name)
in with you select like on pictures, and users table, I don't know/remember what does users table is named and look like but the query will be something like that (put the right table and fields names) :
PHP Code: [ Select ]
//..
 
$q = "SELECT picture_id, name, size FROM picture JOIN user_table USING(username) WHERE firstname LIKE '".$first_name."'";
 
$result = mysql_query($q) or print mysql_error()."<br /";
 
 
  1. //..
  2.  
  3. $q = "SELECT picture_id, name, size FROM picture JOIN user_table USING(username) WHERE firstname LIKE '".$first_name."'";
  4.  
  5. $result = mysql_query($q) or print mysql_error()."<br /";
  6.  
  7.  

and you return $result so that you can browse the results display like I showed you in the beginning on this thread.

and
get pictures_by_first_name($first_name)

am I clear? :-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

erm it comes up

No picture !

no more upload allowed !




and bty no i was not meaning that.. in the user table in the database i have stored all the users info like there username, profile info, firstname, ect. and i want it where a person can search for a firstname of somebody and have it go to header(location "userinfo.php?user=$username");
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

well,

no picture, I guess it's pretty coherent,
Not more upload allowed, I show it in display_upload_form() function, if there is more or equal uploaded pictures files than allowed.
In your case, I think it shows that because when you call the constructor :

PHP Code: [ Select ]
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
 
  1.  
  2. //include the class and connects to the DB
  3.  
  4. $album = new album($user_id, $max_upload);
  5.  
  6.  


$max_upload variable is probably empty.

So if you hadn't put any values for that just before you should give it.
In fact I don't know how you manage that, what does it depend on, so just while you try this script, give a value just before for example

PHP Code: [ Select ]
 
$max_upload = 5;
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
 
  1.  
  2. $max_upload = 5;
  3.  
  4. //include the class and connects to the DB
  5.  
  6. $album = new album($user_id, $max_upload);
  7.  
  8.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

do you understand on what i was trying to do for my user thing?

and bty no i was not meaning that.. in the user table in the database i have stored all the users info like there username, profile info, firstname, ect. and i want it where a person can search for a firstname of somebody and have it go to header(location "userinfo.php?user=$username");


and ermmm


failed av1.jpg 6890 bytes : picture too heavy ! why is it doing that?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Quote:
do you understand on what i was trying to do for my user thing?

do you want a serach enfine for the user (search by firstname, etc...)

Quote:
failed av1.jpg 6890 bytes : picture too heavy ! why is it doing that?

I show it in store_picture() in the picture is too big.
very strange, did you change album::size_limit ?
PHP Code: [ Select ]
//..
 
var $size_limit = 100000;
 
 
  1. //..
  2.  
  3. var $size_limit = 100000;
  4.  
  5.  

that allows till 100000 bytes (100kb)

By the way I realized that I print the values in store_picture() :
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>";
I should have put comment on them .

anyway keep it like that while debuugging and check what is displayed.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

yes i want it where a user can type in a name of a person and it will pull up there username


and no i did not change the file size

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

Post 3+ Months Ago

Ok I will work on a user search engine, when I've got a little time, right now I'm working at office :-).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

basically i have the users firstname in the database and i want it like this

search by firstname of user
||||||||||||||||||| submit


<? header("Location: userinfo.php?user=username");
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

Hey man when do you think you can help me get the pics done?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi man,

are you talking about the size problem?

Could you echo $this->limit at the same time when I show this report, and tell me.

Just like that (in store_picture() function) :

PHP Code: [ Select ]
//...
 
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)  
 
            {
 
               /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
 
                  print "<p>max size set : ".$this->size_limit."</p>";
 
                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']))  
 
            {  
 
                $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(file_exists("pict/".$file['name']))  
 
                $file['name'] .= $this->user_id;  
 
            copy($file['tmp_name'], "pict/".$file['name']);  
 
        }                  
 
    }  
 
 
  1. //...
  2.  
  3. function store_picture()  
  4.  
  5.     {  
  6.  
  7.         //$_FILE is a superglobal so you can get it from there  
  8.  
  9.         foreach ($_FILES as $file)  
  10.  
  11.         {  
  12.  
  13.              print "<p>".$file['name']."<br />";  
  14.  
  15.             print "temp :".$file['tmp_name']."<br />";  
  16.  
  17.             print "type :".$file['type'] ."<br />";  
  18.  
  19.             print "size :".$file['size'] ."<br />";  
  20.  
  21.             print "error :".$file['error'] ."</p>";  
  22.  
  23.             if($file['size'] >= $this->size_limit)  
  24.  
  25.             {
  26.  
  27.                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
  28.  
  29.                   print "<p>max size set : ".$this->size_limit."</p>";
  30.  
  31.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";  
  32.  
  33.                 return false;  
  34.  
  35.             }  
  36.  
  37.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))  
  38.  
  39.             {  
  40.  
  41.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";  
  42.  
  43.                 mysql_query($q) or die(mysql_error()."<br />".$q);  
  44.  
  45.             }  
  46.  
  47.             else  
  48.  
  49.             {  
  50.  
  51.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";  
  52.  
  53.                 return false;  
  54.  
  55.             }  
  56.  
  57.             if(file_exists("pict/".$file['name']))  
  58.  
  59.                 $file['name'] .= $this->user_id;  
  60.  
  61.             copy($file['tmp_name'], "pict/".$file['name']);  
  62.  
  63.         }                  
  64.  
  65.     }  
  66.  
  67.  


Also, right now it's 17:38, I think until 2 hours (about 19/20h here at home), after the job, I will work on the user search engine.I think it won't be very long.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

By the way, could you show all the precise fields names of the user table.

I will use this for my query.

Also do you want the user to switch on what research (firstname or lastname or etc.) or do you want the user to type something and that automatically searches on all?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpJ6MjpD
type :image/pjpeg
size :6890
error :0

max size set :

failed av1.jpg 6890 bytes : picture too heavy !

No picture !


that is what it does

and

the field names of the users tabel is

username
age
city
state
sex
sexuality
firstname
lastname
taken -> is like if they are single or what ever
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok man, I think I got the size problem :

I had f.... the size_limit set in the constructor (function album())


see I replaced
$this->size_limit = $size_limit;
by
$this->size_limit = 100000;

in fact 100000 for 100 kb max (bigger pictures won't be allowed), but if you want to allow less or more feel free to change the value right here.

So here's the correct constructor :

PHP Code: [ Select ]
 
function album($user_id, $nb_limit = 5)  
 
{  
 
        $this->user_id = $user_id;  
 
        $this->nb_limit = $nb_limit;  
 
        $this->size_limit = 100000;  
 
}
 
 
  1.  
  2. function album($user_id, $nb_limit = 5)  
  3.  
  4. {  
  5.  
  6.         $this->user_id = $user_id;  
  7.  
  8.         $this->nb_limit = $nb_limit;  
  9.  
  10.         $this->size_limit = 100000;  
  11.  
  12. }
  13.  
  14.  


Just change this function by the above and try and tell me.

right now 22:11 here , Ijust beginthe seach engine, I hope I finish before the bed:-)

I think I will just add a function called search_user($string) in one of the existing class.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpt2Z04s
type :image/pjpeg
size :6890
error :0

Unknown column 'admin' in 'field list'
INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', 'av1.jpg', '6890', admin)

that is what i get
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Oh sorry it's my fault,

when I add the size echoing, I give you the old script, but we add corrected before the insert statment adding simple quote.

Replace this in store_picture() :

PHP Code: [ Select ]
 
$q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
 
 
  1.  
  2. $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  3.  
  4.  

see I added again the simple quotes ;-)

Also what do you think about that :

the user fill a textbox for his search, in can be a town, a last name or what else, and I do an automatic search on all information about users.
That's it?

or witch fields exactly?

But if it is returning more than one rows what do you want?

shall i show al the resulats with links to userinfo?php so that the user pick the profile he was searching for , or should I directly redirect on userinfo.php for with the first row returned?

among thoses questions everything is possible and everything is easy.

maybe I'll give a little SQL script if I want to use a FULLTEXT index (don't worry you won't have to manage this kind of stuff).

I want to ask one more question,can you tell me if your table is typed MyIsam (or maybe it's innodb or whatelse)?

So I 'm afraid it's getting a little late for ending this night here but I I think here 's no much work on it on tomorow morning.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

Code: [ Select ]
av1.jpg
temp :/tmp/phpXD7jws
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131

No picture !
  1. av1.jpg
  2. temp :/tmp/phpXD7jws
  3. type :image/pjpeg
  4. size :6890
  5. error :0
  6. Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131
  7. No picture !


that is what i get on that and

can it be on the fields that i gave you and as far as in the person profile i want the profile to be userinfo.php?

the mysql engin is MyISAM


here is the phpinfo from my host if that helps any http://phpinfo.hostultra.com/
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

Hey gisele
I just wanted to tell you Thank you for all your help you have gaven me.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,

You're wellcome man !

Ok, I think your warning is a directory problem.

have you created the right directory? a folder named "pict" in the same directory as the script?
Or do whatever you want to store the pictures but think about, fit the right path for copy() in store_picture() function.
I mean either you create the right folder so that it works like that :
PHP Code: [ Select ]
//..
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1. //..
  2.  
  3. copy($file['tmp_name'], "pict/".$file['name']);
  4.  
  5.  

either you manage your own path and change it in something like that :
PHP Code: [ Select ]
//..
 
copy($file['tmp_name'], $your_path.$file['name']);
 
 
  1. //..
  2.  
  3. copy($file['tmp_name'], $your_path.$file['name']);
  4.  
  5.  


first I choose to add a fulltext index.


So anyway don't worry just do thisSQL statment in your db manager.

Code: [ Select ]
ALTER TABLE `users` ADD FULLTEXT `user_search` (
`username` ,
`city` ,
`state` ,
`sex` ,
`sexuality` ,
`firstname` ,
`lastname`
)
  1. ALTER TABLE `users` ADD FULLTEXT `user_search` (
  2. `username` ,
  3. `city` ,
  4. `state` ,
  5. `sex` ,
  6. `sexuality` ,
  7. `firstname` ,
  8. `lastname`
  9. )

in fact I assumed that age was a numeric field and I didn't keep it for the search.

Don't forget these points about fulltext research:

-this index will allow researches on all this field, and return rows depending on a relevance sorting.
-The more you'll have an occurence on a field, the less relevance will be given to it, because it works for an efficient and significative search and there's no need to return a big set of same responses (that's the fulltext philosophy).
-therefore, you have to know that all occurences whose count is over than half of all the rows in the tables will be ignored for the same reason, as useless for the research.
-little words 'the' 'a' 'an' and less than 4 characters lenght will be ignored
-FULLTEXT are only supported on Myisam tables

if you're curious about it, I think this link tell you in a better english than mine How does it work :-) :


http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Then the function, you can put it in database class, for example next to getUserComments().
you just have to call it, putting is $string as parameter the result of a form for example with a textbox, that will be the string for the research.
It shows the username founded thanks the string, with links to userinfo.php
PHP Code: [ Select ]
 
function search_user($string)
 
{
 
   $q = "SELECT username FROM users WHERE MATCH (username , city, state, sex, sexuality, firstname, lastname) AGAINST ('".$string."');
 
   $r =  mysql_query($q) or die (mysql_error()."<br />".$q);
 
   if(mysql_num_rows($r))
 
   {
 
      print "<p><b>Results : </b></p>\n<p>";
 
      while($data = mysql_fetch_row($r))
 
         print "<a href=\"userinfo.php?username=".$data[0]."\">".$data[0]."</a>\n";//link for each username founded
 
      print "</p>\n";
 
   }
 
   else
 
      print "<p><b>no result found</b></p>\n";
 
}
 
 
  1.  
  2. function search_user($string)
  3.  
  4. {
  5.  
  6.    $q = "SELECT username FROM users WHERE MATCH (username , city, state, sex, sexuality, firstname, lastname) AGAINST ('".$string."');
  7.  
  8.    $r =  mysql_query($q) or die (mysql_error()."<br />".$q);
  9.  
  10.    if(mysql_num_rows($r))
  11.  
  12.    {
  13.  
  14.       print "<p><b>Results : </b></p>\n<p>";
  15.  
  16.       while($data = mysql_fetch_row($r))
  17.  
  18.          print "<a href=\"userinfo.php?username=".$data[0]."\">".$data[0]."</a>\n";//link for each username founded
  19.  
  20.       print "</p>\n";
  21.  
  22.    }
  23.  
  24.    else
  25.  
  26.       print "<p><b>no result found</b></p>\n";
  27.  
  28. }
  29.  
  30.  

well in fact I didn't really understand if you were willing to display the results with all info directly in userinfo.php, or just show the username founded , with built links so that we can pick the right user, and see his own information after in userinfo.php.

I didn't make up the research form, just the function that take the result of i ($string) and do the research.So once you have a result, anywhere in your site you just have to call search_user($string).
$string is the string typed for the research.

Tell what you exactly want, maybe you want put the whole stuff in userinfo.php (research form + user_search() call)?

feel free to ask question.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

hey i dont understand on what you mean for the picture thing
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

well,

you will have to stored the picture in a directory on the server won't you?

in the table, I just store informations on the pictures (name, etc.) but since a picture is a binary file, it has to be put somewhere on the server once it is uploaded.
(first they come to the server as a temporary file, and then copy() will put them in a directory so that you can use them later (show them, whatelse).
You will store all of them in the same directory on the web server that you have created.

Think about where you put the php scripts of all this stuff, at the same place just create a folder named "pict" for instance so that this (in store_picture() ) could work :
PHP Code: [ Select ]
//...
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1. //...
  2.  
  3. copy($file['tmp_name'], "pict/".$file['name']);
  4.  
  5.  


the first parameter $file['tmp_name'] is just the file like it is uploaded as a temporary file (for example :/tmp/phpXD7jws ).

and the second one

"pict/".$file['name'] is where you want to copy the picture on the server.(assuming you have created a folder named "pict" in the same directory of your PHP scripts.

Did you get it?
otherwise feel free to ask for the points that you can't understand ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

Code: [ Select ]
av1.jpg
temp :/tmp/phpOyGhtP
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 144

No picture !
  1. av1.jpg
  2. temp :/tmp/phpOyGhtP
  3. type :image/pjpeg
  4. size :6890
  5. error :0
  6. Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 144
  7. No picture !


that is what i get and here is the code if that helps any

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


Is it still posting it to a user id or username and you can post to a username by $username
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

OK , I added a little somthing that'll create by itself the folder if it doesn't exist:

PHP Code: [ Select ]
 
if(!is_dir("pict"))
 
               mkdir ("pict", 0700);  
 
 
  1.  
  2. if(!is_dir("pict"))
  3.  
  4.                mkdir ("pict", 0700);  
  5.  
  6.  




So all is left to do is replace the store_picture() function by this :

PHP Code: [ Select ]
 
   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)    
 
            {  
 
                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
 
                    print "<p>max size set : ".$this->size_limit."</p>";  
 
                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']))    
 
            {    
 
                $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);    
 
            if(file_exists("pict/".$file['name']))    
 
                $file['name'] .= $this->user_id;    
 
            copy($file['tmp_name'], "pict/".$file['name']);    
 
        }                    
 
    }  
 
 
  1.  
  2.    function store_picture()    
  3.  
  4.     {    
  5.  
  6.         //$_FILE is a superglobal so you can get it from there    
  7.  
  8.         foreach ($_FILES as $file)    
  9.  
  10.         {    
  11.  
  12.              print "<p>".$file['name']."<br />";    
  13.  
  14.             print "temp :".$file['tmp_name']."<br />";    
  15.  
  16.             print "type :".$file['type'] ."<br />";    
  17.  
  18.             print "size :".$file['size'] ."<br />";    
  19.  
  20.             print "error :".$file['error'] ."</p>";    
  21.  
  22.             if($file['size'] >= $this->size_limit)    
  23.  
  24.             {  
  25.  
  26.                 /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
  27.  
  28.                     print "<p>max size set : ".$this->size_limit."</p>";  
  29.  
  30.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
  31.  
  32.                 return false;    
  33.  
  34.             }    
  35.  
  36.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
  37.  
  38.             {    
  39.  
  40.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  41.  
  42.                 //mysql_query($q) or die(mysql_error()."<br />".$q);    
  43.  
  44.                             }    
  45.  
  46.             else    
  47.  
  48.             {    
  49.  
  50.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
  51.  
  52.                 return false;    
  53.  
  54.             }
  55.  
  56.             if(!is_dir("pict"))
  57.  
  58.                mkdir ("pict", 0700);    
  59.  
  60.             if(file_exists("pict/".$file['name']))    
  61.  
  62.                 $file['name'] .= $this->user_id;    
  63.  
  64.             copy($file['tmp_name'], "pict/".$file['name']);    
  65.  
  66.         }                    
  67.  
  68.     }  
  69.  
  70.  


And then tell me if you still have this warning.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpUhajwV
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 146

No picture !


thats what i get
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Well,

it maybe because of the chmod of the parent folders but there's no reason if you can synchronize the files in.

please try without a dedicated folder.
replace you function by this (I remove the folder stuff and pictures will be copied in the same directory of the php script )(in fact i'm still searching for this damned trouble but try this :-) ):
PHP Code: [ Select ]
 
php 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)    
 
            {    
 
                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
 
                    print "<p>max size set : ".$this->size_limit."</p>";    
 
                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']))    
 
            {    
 
                $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(file_exists($file['name']))    
 
                $file['name'] .= $this->user_id;    
 
            copy($file['tmp_name'], $file['name']);    
 
        }                    
 
    }
 
 
  1.  
  2. php function store_picture()    
  3.  
  4.     {    
  5.  
  6.         //$_FILE is a superglobal so you can get it from there    
  7.  
  8.         foreach ($_FILES as $file)    
  9.  
  10.         {    
  11.  
  12.              print "<p>".$file['name']."<br />";    
  13.  
  14.             print "temp :".$file['tmp_name']."<br />";      
  15.  
  16.             print "type :".$file['type'] ."<br />";      
  17.  
  18.             print "size :".$file['size'] ."<br />";    
  19.  
  20.             print "error :".$file['error'] ."</p>";    
  21.  
  22.             if($file['size'] >= $this->size_limit)    
  23.  
  24.             {    
  25.  
  26.                 /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
  27.  
  28.                     print "<p>max size set : ".$this->size_limit."</p>";    
  29.  
  30.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
  31.  
  32.                 return false;    
  33.  
  34.             }    
  35.  
  36.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
  37.  
  38.             {    
  39.  
  40.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  41.  
  42.                 //mysql_query($q) or die(mysql_error()."<br />".$q);    
  43.  
  44.                             }    
  45.  
  46.             else    
  47.  
  48.             {    
  49.  
  50.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
  51.  
  52.                 return false;    
  53.  
  54.             }
  55.  
  56.            
  57.  
  58.             if(file_exists($file['name']))    
  59.  
  60.                 $file['name'] .= $this->user_id;    
  61.  
  62.             copy($file['tmp_name'], $file['name']);    
  63.  
  64.         }                    
  65.  
  66.     }
  67.  
  68.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

jarhead.jpg
temp :/tmp/phpTtXqxK
type :image/pjpeg
size :42413
error :0


Warning: copy(jarhead.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 145

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

Post 3+ Months Ago

OK, I tried on my FTP
you can make tries on it
http://monsieurgisele.free.fr/photos/public/upload.php


And it worked like can see with this (contents the class definition + something below to make it run, I comments my db connexion :-) ) :

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

Post 3+ Months Ago

Ok it's getting late here, see you tomorow morning. ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 674
  • Loc: Conroe, Texas

Post 3+ Months Ago

jarhead.jpg
temp :/tmp/phpujPw2C
type :image/pjpeg
size :42413
error :0


Warning: copy(pict/jarhead.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131
SELECT picture_id, name, size FROM picture WHERE user_id=1

Name Size Picture Action
jarhead.jpg 42413 Delete

if you want to you can sign up and see for yourself..
http://www.gothicgreenwire.com/ggwnew/
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,
I believe you :-)
Well, what about trying move_uploaded_file()?

please try to replace :
PHP Code: [ Select ]
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1.  
  2. copy($file['tmp_name'], "pict/".$file['name']);
  3.  
  4.  


by
PHP Code: [ Select ]
 
move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
 
 
  1.  
  2. move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
  3.  
  4.  

in store_picture().

By the way, I realize I left a print, just in display_album() just before before the select query, that why it is showed when you rin it :-)
PHP Code: [ Select ]
 
print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
 
  1.  
  2. print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  3.  
  4.  

you just have to remove the print ;-)

yeah and you can try to upload on my link if you want just to see how ot should work on yours :

http://monsieurgisele.free.fr/photos/public/upload.php
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 97 posts
  • Users browsing this forum: No registered users and 85 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
 
 

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