Help! With Image Uploading Problem - Need it to rename file

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Help! With Image Uploading Problem - Need it to rename file
xtrax1
CZ Active Member
 Codezwiz Site Donator
xtrax1 has been a member for over 19 year's 19 Year Member
Gender: Male
Status: Offline
Joined: Feb 18, 2005
0.02 posts per day
Posts: 107
Points: 3,824
   
Wow its been awhile....

I got a huge dilemma, I have a huge image gallery where users can upload images etc, but we noticed a problem ...

Some user’s files are getting over-written with other users files upon upload...!! icon_redface.gif

We are willing to pay for your time, or make a donation!

Now what we need to know is someone can help us make the UploadFile.php rename the image file before storing it into the temp folder!

Here is the code:

<?PHP

function listcategories($dir){

  global $gallerypath, $prefix, $db;

  $dossier = opendir($dir);

  $category = "";

  while ($file = readdir($dossier)) {

if ($file != "." && $file != ".." && $file!="thumb"){

if (is_dir($dir."/".$file)){

         $galloc  = substr($dir."/".$file, strlen("$gallerypath/"));

         $result = $db->sql_query("select gallid from $prefix"._gallery_categories." where galloc='$galloc'");

         if ($result) {

            list($gid) = $db->sql_fetchrow($result);

            $category .= "$gid ";

         }

         $category .= listcategories("$dir/$file");

        }

     }

  }

  return $category;

}

function upload_file() {

   global $name, $font, $galleryvar, $basepath, $user, $gallerypath, $prefix, $db, $baseurl;

   galleryHeader();

   OpenTable();

   $size = $maxSize/1000;

   $nav = navigationGall();

   echo "<table border=\"0\" width=\"100%\">

          <tr>

         <td width=\"100%\">

            $nav<br />

            <center><font class=\"".$font['title']."\">"._GALUPLOADMEDIA."</font></center>

         </td>

          </tr>

        <tr><td align=\"center\">";

   if (is_user($user) || !$galleryvar['anonpostpics']) {

   echo "   <form enctype=\"multipart/form-data\" action=\"wallpaper.html\" method=\"post\">

        <input type=\"hidden\" name=\"do\" value=\"upload\">

        <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr>

          <td align=\"left\" valign=\"top\" >

         <font class=\"".$font['normal']."\">"._GALSELECTCATEGORY."</font><br>

                  <select name=\"Category\">";

         $categories = listcategories("$gallerypath");

         if (isset($categories) && $categories!="") {

            $categories = explode(" ", trim($categories));

            while(list($key, $val) = each($categories)) {

               if (is_user($user))

                  $result = $db->sql_query("select gallid, gallname, parent from $prefix"._gallery_categories." where visible>0 and gallid=".$val);

               else

                  $result = $db->sql_query("select gallid, gallname, parent from $prefix"._gallery_categories." where visible>1 and gallid=".$val);

               if ($db->sql_numrows($result)>0) {

                  list($gallid, $gallname, $parent) = $db->sql_fetchrow($result);

                  $nbtabs = indent($gallid);

                  $tab = "";

                  for($k=0; $k<$nbtabs; $k++)

                     $tab .= "&nbsp;&nbsp;";

                  echo "<option value=\"$gallid\">$tab$gallname</option>\n";

               }

            }

         }

                  echo "

         </select><br><br>

         <font class=\"".$font['normal']."\">"._GALMEDIANAME."<br></font>

            <input type=\"text\" name=\"MediaName\" size=\"30\" value=\"\"><br><br>

              <font class=\"".$font['normal']."\">"._GALFILENAME."</font><br>";

         if ($galleryvar['limitSize'])

            echo "<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$maxSize\">";

         echo "

            <input type=\"file\" name=\"userfile\" size=\"20\"><br><br>

              <font class=\"".$font['normal']."\">"._GALSUBMITTER."</font><br>";

            if (is_user($user)) {

               $userdata=cookiedecode($user);

               echo "<input type=\"hidden\" name=\"Submitter\" value=\"".$userdata[1]."\">\n";

               echo "<b>".$userdata[1]."</b><br /><br />";

            } else

               echo "<input type=\"text\" name=\"Submitter\" size=\"14\"><br><br>";

           echo "

           </td>

           <td align=\"left\" valign=\"top\"><font class=\"".$font['normal']."\">"._GALDESCRIPTION."</font><br>

              <textarea  name=\"Description\" rows=\"10\" cols=\"35\"></textarea>

           </td></tr>

      <tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Upload\" name=\"add\"></td></tr>

             </table>

             </form>

      <table border=\"0\">

      <tr>

         <td>

         <h5>"._GALUPLOADMEDIAGUIDLINES."</h5>

            "._GALUPLOADMEDIAGUIDLINES1."<br /><br />

         <center><font class=\"".$font['normal']."\">";

         if ($galleryvar['limitSize'])

            echo "".sprintf(_GALMAXSIZEPOST,$size)."<br>";

         echo _GALCLICKONCE."</center>

         </font>

         </td>

      </tr>

      </table>";

   } else

        echo "<p align=\"center\"><font class=\"".$font['normal']."\">"._GALREGISTER2POSTPICS."</font></p>";

   echo "</td></tr>"

         ."</table>";

   CloseTable();

   galleryFooter();

}

function Add($gid, $file, $submitter, $medianame, $description, $userfile, $userfile_name, $userfile_size) {

    global $user, $font, $galleryvar, $basepath, $temppath, $prefix, $db;

    $sql = "select img from $prefix"._gallery_pictures." where gid=$gid and img='$file'";

    $result = $db->sql_query($sql);

    $numrows = $db->sql_numrows($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];

       }

       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

       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

       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);

      if ($upload_return=="OK") {

         $ext = substr($file, (strrpos($file,'.') +  1));

         list($type) = $db->sql_fetchrow($db->sql_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)";

         $db->sql_query($sql);

      } else

         return $upload_return;

      return "OK";

   }

    }

}

?>


We look forward to your reply!

XtraX1


Back to top Reply with quote
#2   
Telli
Site Admin
Telli has been a member for over 20 year's 20 Year Member
Occupation: Self Employed
Age: 45
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.06 posts per day
Posts: 8089
Points: 494,430
   
Can you attach a copy of the database table (gallery_pictures)? You can PM to me if thats better. I will also need the function file with the module (where the upload function is).




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: Help! With Image Uploading Problem - Need it to rename f
xtrax1
CZ Active Member
 Codezwiz Site Donator
xtrax1 has been a member for over 19 year's 19 Year Member
Gender: Male
Status: Offline
Joined: Feb 18, 2005
0.02 posts per day
Posts: 107
Points: 3,824
   
Hello Telli,

Thank you for your quick response, I just sent you a pm with the files you requested!

XtraX1



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
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 cannot attach files in this forum
You cannot download files in this forum