Web Analytics Made Easy -
StatCounter Adding a number to end of uploaded file - CodingForum

Announcement

Collapse
No announcement yet.

Adding a number to end of uploaded file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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 
    ZCE

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎