changing image name after uploading

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • dannysheps@hotmail.com
    Second Lieutenant

    • Feb 2008
    • 138

    changing image name after uploading

    Hello
    does anaybody know how can i add a line of code that will change the name of the image uploaded to avoid similarity cus then the computer delete and overwrite the old file.

    can i add it to the ABVFP ?
    can i add the Record_Nr that always increasing ?(and like that it will never be the same)

    thanks

    *the code
    Code:
    //--------- Move the files to destination----------------
    $nduploadfolder1 = basename($nduploadfolder);
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Size[$i] < $ndfilesize1 and $upload_Size[$i] >0)
    {
    $uploadFile = "$nduploadfolder1/".$upload_Name[$i];
    if (!is_dir(dirname($uploadFile)))
      {
        @RecursiveMkdir(dirname($uploadFile));
      }
    else
      {
      @chmod(dirname($uploadFile), 0777);
      }
    @move_uploaded_file( $upload_Temp[$i] , $uploadFile);
    chmod($uploadFile, 0644);
    }
    }
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: changing image name after uploading

    Make it:

    $nduploadfolder1 = basename($nduploadfolder);
    for ($i = 0; $i < count($upload_Name); $i++) {
    if ($upload_Size[$i] < $ndfilesize1 and $upload_Size[$i] >0)
    {
    $uploadFile = date(Y_m_d)."_$nduploadfolder1/".$upload_Name[$i];
    if (!is_dir(dirname($uploadFile)))
    {
    @RecursiveMkdir(dirname($uploadFile));
    }
    else
    {
    @chmod(dirname($uploadFile), 0777);
    }
    @move_uploaded_file( $upload_Temp[$i] , $uploadFile);
    chmod($uploadFile, 0644);
    }
    }

    You can't use the Record_id, unless you
    1. Move the file moving code AFTER the database INSERT command
    2. Add a line, just after the insert query: $Recordid = mysql_insert_id;
    2. Make the line i added above:
    $uploadFile = $Recordid."_$nduploadfolder1/".$upload_Name[$i];
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • dannysheps@hotmail.com
      Second Lieutenant

      • Feb 2008
      • 138

      #3
      Re: changing image name after uploading

      hi
      no need for the id # as long as it will give to it a different appearence and wouldnt over write another file.
      but i though about if the same file name would be uploaded in the same day ?!

      can we make it as a random number or something like that ?

      instead of that :
      $uploadFile = date(Y_m_d)."_$nduploadfolder1/".$upload_Name[$i];

      well do :
      $uploadFile = rand()."_$nduploadfolder1/".$upload_Name[$i];

      thanks

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: changing image name after uploading

        Yes, you can use that, but this way you will have no reference of where the file belongs. The use of the record id ill provide a direct relationship among the database record and the file itself.

        This is a good idea and i will adopt it for ABVFP. Look for the updated code later in the day. I will post in this same thread to let you know.
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • navaldesign
          General & Forum Moderator

          • Oct 2005
          • 12080

          #5
          Re: changing image name after uploading

          I have updated the script that is now using a 10 chrs prefix for the uploaded files names. I did not use rand() for reasons of my own, neither the Record id (there are users that don't store the info in the database, so no Record id exists) but i believe that this is not important to you.

          You can now download the updated version from my site
          Navaldesign
          Logger Lite: Low Cost, Customizable, multifeatured Login script
          Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
          DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
          Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

          Comment

          • dannysheps@hotmail.com
            Second Lieutenant

            • Feb 2008
            • 138

            #6
            Re: changing image name after uploading

            hi
            thanks alot.

            Comment

            • dannysheps@hotmail.com
              Second Lieutenant

              • Feb 2008
              • 138

              #7
              Re: changing image name after uploading

              works fine...thanks again

              Comment

              • kadm
                Sergeant

                • Mar 2008
                • 23

                #8
                Re: changing image name after uploading

                Hi,
                My file that i upload does not save and/or make i directory.
                When i recieve the email it does not contain any fiel/or referance, can you help please Kurt

                Comment

                • navaldesign
                  General & Forum Moderator

                  • Oct 2005
                  • 12080

                  #9
                  Re: changing image name after uploading

                  Hi Kurt,

                  There have been QUITE a lot of changes in ABVFP lately, and at a certain point it would not save. If you downloaded at that moment, there might be an issue.

                  Please download the zip now, and replace only the file dbts_abvfp.php
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment

                  • kadm
                    Sergeant

                    • Mar 2008
                    • 23

                    #10
                    Re: changing image name after uploading

                    Hi Navaldesign,
                    I am busy taking your advise and let you know later. By way Thanks for putting so much effort in, we really appreciate it. Keep well Kurt.

                    Comment

                    • kadm
                      Sergeant

                      • Mar 2008
                      • 23

                      #11
                      Re: changing image name after uploading

                      Hi Navaldesign,
                      Wow great work you did, it is working perfect now, except for a small detail.
                      If the cofirmation email is sent, it has no " from " email and it is blank. How could we insert the "from email " in.
                      I know that i recieve alot of spam emails.
                      If the "email address" (From :) has nothing in it, then it throws it spam.
                      Thank you in advance, Kurt.

                      Comment

                      • navaldesign
                        General & Forum Moderator

                        • Oct 2005
                        • 12080

                        #12
                        Re: changing image name after uploading

                        Fixed! Thank you.

                        Please download again and replace once more the file. dbts_abvfp.php. Sorry!
                        Navaldesign
                        Logger Lite: Low Cost, Customizable, multifeatured Login script
                        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                        Comment

                        • kadm
                          Sergeant

                          • Mar 2008
                          • 23

                          #13
                          Re: changing image name after uploading

                          Thanks Naveldesign,
                          Once again the master has done it again, works Excellently.
                          Wonder if you could help me with our next problem, looked all over, did'nt seem to get a solution.
                          I have made a small employee data base, requesting 1) name 2) email 3) phone and picture to be added of employee.
                          Created data base as employees yet if it goes to the php page it gives thiabout47fa72e8723c57.85659106
                          184714942547fa72e8723ec5.61369709
                          dcc9b91a57cc1b899c0f9eb23adee59a
                          Warning: move_uploaded_file(images/favicon.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/sgfcjgmq/public_html/employees/add.php on line 65

                          Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpbyWgqh' to 'images/Jill.png' in /home/sgfcjgmq/public_html/employees/add.php on line 65
                          Sorry, there was a problem uploading your file. > s error.
                          Could you help

                          Comment

                          • navaldesign
                            General & Forum Moderator

                            • Oct 2005
                            • 12080

                            #14
                            Re: changing image name after uploading

                            I can't know what the structure of your script is and if it defines as temp folder something else than the default temp. So i can't really give you a good answer.

                            The error message says that it simply doesn't find the uploaded file, but it doesn't give any info on the reason. Also it would be necessary to analyze the function move-uploaded-file to see how it works and why it causes the problem.
                            Navaldesign
                            Logger Lite: Low Cost, Customizable, multifeatured Login script
                            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                            Comment

                            • kadm
                              Sergeant

                              • Mar 2008
                              • 23

                              #15
                              Re: changing image name after uploading

                              Ok i have being working on it a bit here is the page html
                              <?php
                              //creates a unique id with the 'about' prefix
                              $a = uniqid(about);
                              echo $a;
                              echo "<br>";
                              //creates a longer unique id with the 'about' prefix
                              $b = uniqid (about, true);
                              Echo $b;
                              echo "<br>";
                              //creates a unique ID with a random number as a prefix - more secure than a static prefix
                              $c = uniqid (rand (),true);
                              echo $c;
                              echo "<br>";
                              //this md5 encrypts the username from above, so its ready to be stored in your database
                              $md5c = md5($c);
                              echo $md5c;
                              ?>
                              <?php
                              //This is the directory where images will be saved
                              $target = "images/";
                              $target = $target . basename( $_FILES['photo']['name']);
                              //This gets all the other information from the form
                              $name=$_POST['name'];
                              $email=$_POST['email'];
                              $phone=$_POST['phone'];
                              $pic=($_FILES['photo']['name']);
                              // Connects to your Database
                              mysql_connect("localhost", "sgfcjgmq_admin", "admin") or die(mysql_error()) ;
                              mysql_select_db("sgfcjgmq_employees") or die(mysql_error()) ;
                              //Writes the information to the database
                              mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;
                              //Writes the photo to the server
                              if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
                              {
                              //Tells you if its all ok
                              echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
                              }
                              else {
                              //Gives and error if its not
                              echo "Sorry, there was a problem uploading your file.";
                              }
                              ?>
                              and it gives this error now

                              about47fa8171b58a96.26254278
                              37176010047fa8171b58cc8.04798424
                              115fae05c49aeb07404d2c98b0c849c5 Sorry, there was a problem uploading your file. >
                              Thank you register and photo uploaded
                              Access denied for user 'sgfcjgmq_admin'@'localhost' to database 'sgfcjgmq_employee'

                              Comment

                              Working...
                              X