PHP Web Host - Quality Web Hosting For All PHP Applications Sign up for PayPal and start accepting credit card payments instantly
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
prekill
Regular
Regular


Joined: Oct 22, 2005
Posts: 97

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

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
Moderator


Joined: Apr 30, 2004
Posts: 2749

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

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
View user's profile Send private message Visit poster's website
prekill
Regular
Regular


Joined: Oct 22, 2005
Posts: 97

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

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.
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum