Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    122
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Cool Adding a number to end of uploaded file

    I have this code:

    PHP Code:
     $rand rand(1,9999999999);
       
    $filename $_FILES['site_url']['name']; // Get the name of the file (including file extension).
       
    $filename preg_replace('/\s/''_'$filename);
       
    $ext substr($filenamestrpos($filename,$rand,'.'), strlen($filename)-1); // Get the extension from the filename. 
    And I want to know if there is a way to add random numbers to the end of a code? If so, thanks.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You want to turn `filename.png` into `filename.12345.png`?
    PHP Code:
    $filename 'filename.png';

    $file_parts explode'.'$filename);

    $filename_rand implode'.', array(
         
    $file_parts[0],
         
    mt_rand1000099999 ),
         
    $file_parts[1],
    ) );

    echo 
    $filename_rand// filename.12345.png 

  • Users who have thanked kbluhm for this post:

    Xaqa (09-08-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •