Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 7.6
Author Message
prekill
Worker
Worker



Joined: Oct 22, 2005
Posts: 201

PostPosted: Thu Oct 25, 2007 2:00 pm Reply with quote

Hey guys,

I have my egallery working just fine! I now started to have this small problem. my gallery is getting really big (lots of users sends lots of images). on upload, my_egallery should check if the filename/medianame already exsists in the database and if so ask the user to change the media name.

my_egallery faild this proccess and I keep on overwrithing exsisting images.

the problem in my opinion is in the uploadFile.php under the function Add:
Code:


function Add($gid, $file, $submitter, $medianame, $description, $userfile, $userfile_name, $userfile_size) {
    global
       $user,
        $font,
        $galleryvar,
       $basepath,
        $temppath,
       $prefix
    ;

    $sql = "select img from $prefix"._gallery_pictures." where gid=$gid and img='$file'";
    //echo $sql;
    $result = mysql_query($sql);
    $numrows = mysql_num_rows($result);
    $navgall = navigationGall();
   
    if ($file==$galleryvar['GalleryPictureName'] || $numrows>0) {
   galleryHeader();
   OpenTable();
   print '<table border="0" width="100%" align="center" cellpadding="0">'
       .'<tr><td>'.$navgall;
   
   echo "<br>";
   echo "<center><b>"._GALPICALREADYEXT."</b><br><br>"
       .""._GOBACK."";
   print '</td></tr></table>';
   CloseTable();
   galleryFooter();
    }
    else {
       if(is_user($user)) {
      $user2 = base64_decode($user);
      $cookie = explode(":", $user2);
      cookiedecode($user);
      $submitter = $cookie[1];   
       }

   // Check if Media Name exist
       if (!isset($medianame) || $medianame=="") {
      galleryHeader();
      echo "<br>";
      OpenTable();
      print '<table border="0" width="100%" align="center" cellpadding="0">'
       .'<tr><td>'.$navgall;
      echo "<br>";
      echo "<center><b>"._GALPICNONAME."</b><br><br>"
          .""._GOBACK."";
      print '</td></tr></table>';
      CloseTable();
      galleryFooter();
       }
       else
   // Check if Description exist
       if (!isset($description) || $description=="") {
      galleryHeader();      
      echo "<br>";
      OpenTable();
      print '<table border="0" width="100%" align="center" cellpadding="0">'
       .'<tr><td>'.$navgall;
      echo "<center><b>"._GALPICNODESC."</b><br><br>"
          .""._GOBACK."";
      print '</td></tr></table>';
      CloseTable();
      galleryFooter();
       }
       else
   // Check if Description exist
       if (!isset($submitter) || $submitter=="") {
      galleryHeader();      
      echo "<br>";
      OpenTable();
      print '<table border="0" width="100%" align="center" cellpadding="0">'
       .'<tr><td>'.$navgall;
      echo "<br>";
      echo "<center><b>"._GALPICNOSUBMITTER."</b><br><br>"
          .""._GOBACK."";
      print '</td></tr></table>';
      CloseTable();
      galleryFooter();
       }
       else {
      $medianame = FixQuotes($medianame);
      $description = FixQuotes($description);
      $wdir = "/";
      $upload_return = UploadFile($temppath, $userfile, $userfile_name, $userfile_size);
      //echo "public uploadFile.php : $upload_return<br>";
      if ($upload_return=="OK") {
         $ext = substr($file, (strrpos($file,'.') +  1));
         list($type) = mysql_fetch_row(mysql_query("select filetype from $prefix"._gallery_media_types." where extension='$ext'"));
         $wdir = "/";

         switch($type) {
            case 1 :
               $size = @getimagesize($temppath.$wdir.$file);
               break;
            case 3 :
               $size[0] = 320;
               $size[1] = 240;
               break;
            default:
               $size[0] = 0;
               $size[1] = 0;
               break;
         }
         $file = traite_nom_fichier($file);
         if ($size!=NULL)
            $sql = "insert into $prefix"._gallery_pictures_newpicture." (pid, gid, img, counter, submitter, date, name, description, votes, rate, extension, width, height) values(NULL, $gid, '$file', 0, '$submitter', now(), '$medianame', '$description', 0, 0, '$ext', ".$size[0].", ".$size[1].")";
         else
            $sql = "insert into $prefix"._gallery_pictures_newpicture." (pid, gid, img, counter, submitter, date, name, description, votes, rate, extension, width, height) values(NULL, $gid, '$file', 0, '$submitter', now(), '$medianame', '$description', 0, 0, '$ext', 0, 0)";
         //echo $sql;
         mysql_query($sql);
      }
      else
         return $upload_return;
      return "OK";
   }
    }
}


take a look at this part that should check if media name exsist:
Code:


   // Check if Media Name exist
       if (!isset($medianame) || $medianame=="") {
      galleryHeader();
      echo "<br>";
      OpenTable();
      print '<table border="0" width="100%" align="center" cellpadding="0">'
       .'<tr><td>'.$navgall;
      echo "<br>";
      echo "<center><b>"._GALPICNONAME."</b><br><br>"
          .""._GOBACK."";
      print '</td></tr></table>';
      CloseTable();
      galleryFooter();
       }


As I was trying to solve this I found out my_egallery has 2 id's for file/media name in the database: table 'img' which is the real file name (ex. 1.jpg) and table 'name' which is the name the user give to the image (ex. nice flower).

for some unknown reason the coder who wrote this gallery is trying to check if the 'name' is already exsist in the database and not 'img' which is much more logical and what it should really check in order to prevent duplicated images and file names.

After playing with the code for hours now (I think it should really be simple to replace the checking to file name instad of user file name I gusse I just too dumm) I just gave up.

Does anyone have any idea on how to change the checking to file name?

thank you very much,

Roy
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Oct 25, 2007 11:39 pm Reply with quote

I'm guessing its querying on "gallery_pictures" table and its failing? If the query is failing, you'd probably be able to capture this error and deal with it so it doesn't execute the more code

What I would try is setting indexes on that table to speed up searching, esp if its only based on one field like the image name

_________________
- Star Wars Rebellion Network -

Need help? Nuke Patched Core, Coding Services, Webmaster Services 
View user's profile Send private message Visit poster's website
prekill







PostPosted: Fri Oct 26, 2007 6:28 am Reply with quote

evaders99, Sounds great! checking if the image file name already exsists is the only importent thing I need to check.. the rest doesnt really metter.

I am not really a coder, can someone give me a little help with this?
Is it complicated?

Thank you very much.
 
Display posts from previous:       
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 7.6

View next topic
View previous topic
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©