create directory name based on system date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ogo796
    New Member
    • Jan 2008
    • 44

    create directory name based on system date

    hi everyone i upload file each an every day so i want to keep track of how many files i uploade a day by creating new directory everytime when i uploade base on the system date.

    example
    the new directory must be name according to the system date:


    $newdir = "system date";

    i want my directory name to look like 30January2007
    i will be glad if i can get help.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Probably a few methods.
    This is a simple example
    [PHP]$date = date('dFY');
    mkdir('/path/to/directory/'.$date);[/PHP]

    Comment

    • ogo796
      New Member
      • Jan 2008
      • 44

      #3
      hi thanks it works .but my script does'nt wanna copy files to the directory that have been created.

      i have a source file and destination file:
      $source = $_FILES['uploaded']['name'];
      and
      $destfile= "/home/FTP-shared/comp/". basename(
      $_FILES['uploaded']['name']) ;

      when i try to uploade it tells me that fail to open the stream.
      file not copied.

      i will be glad if you can give me idea about that.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        my script does'nt wanna copy files to the directory
        Can you describe (with code) how you are trying to do this.

        Comment

        • ogo796
          New Member
          • Jan 2008
          • 44

          #5
          $Tdate = date('dFY');
          $Tdir ="/home/FTP-shared/comp/"; //destination
          $source = $_FILES['uploaded']['name'];
          echo $Tdir."/".$Tdate."< br/>";
          if(file_exists( $Tdir."/".$Tdate))
          {
          copy($source, $Tdir."/".$Tdate."/");
          }
          else
          // check if the directory exist or not

          {
          mkdir($Tdir."/".$Tdate);
          echo"directory has been created !<br/>";
          echo $source." in new uploader<br/>";
          copy( $source, $Tdate."/".$destfile );
          }

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            My understanding is the browser renames the uploaded file 'temp_name'
            'name' is the original filename.
            So to access the file from the browser you need
            [PHP]$_FILES['uploadedfile']['tmp_name'];[/PHP]
            But I need to revise this subject myself.
            Other problems are file permissions and sometimes needing the full path string.
            Would move_uploaded_f ile() be a better option.
            copy() is meant for files already in the system

            Comment

            • ogo796
              New Member
              • Jan 2008
              • 44

              #7
              Hi thank a lot

              yes i understand but the problem is i want to keep the original file name i the file that i am uploading.cause the uploaded file i re name and upload them.so i dont want the renamed file in the completed folder. other altenative based of my explanation.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                What code green said is correct.

                You need to use move_uploaded_f ile

                this wont change the file name:

                [php]
                move_uploaded_f ile
                ($_FILES['uploaded]['tmp_name'],
                "path/to/directory/" . $_FILES['uploaded']['name']);
                [/php]

                Note, please check you use only the needed amount of forward slashes to seperate directories (1); from the looks of it you assign more than this.

                Comment

                • code green
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1726

                  #9
                  My point was, I'm not sure you have a choice.
                  I've only played with this a couple of times, but
                  to access the file you need to use the $_FILE 'temp_name' or is it 'tmp_name'
                  The original file name is in the index ['name'].

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by code green
                    My point was, I'm not sure you have a choice.
                    I've only played with this a couple of times, but
                    to access the file you need to use the $_FILE 'temp_name' or is it 'tmp_name'
                    The original file name is in the index ['name'].
                    Preciselly(sp?)

                    and it's tmp_name

                    :)

                    Comment

                    • code green
                      Recognized Expert Top Contributor
                      • Mar 2007
                      • 1726

                      #11
                      Thanks for the help markusn00b

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #12
                        @ogo: Have a look at this tutorial for file upload using php; you could easily intergrate your directory creation into it (this tutorial is alot cleaner than your way of it.)

                        @code 9f27410725ab8cc 8854a2769c7a516 b8: no problamo!

                        Comment

                        • ogo796
                          New Member
                          • Jan 2008
                          • 44

                          #13
                          thanks i use the move_uploaded_f ile it works but it dosen't wanna create the folder again.but i will look at it.
                          Thanks very much you help me through out this

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            Originally posted by ogo796
                            thanks i use the move_uploaded_f ile it works but it dosen't wanna create the folder again.but i will look at it.
                            Thanks very much you help me through out this
                            Well post up the code you now have (use code tags!) and we'll help you further.

                            Comment

                            Working...