...

View Full Version : Adding a number to end of uploaded file



Xaqa
09-08-2011, 12:05 AM
I have this 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($filename, strpos($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. :)

kbluhm
09-08-2011, 12:53 AM
You want to turn `filename.png` into `filename.12345.png`?


$filename = 'filename.png';

$file_parts = explode( '.', $filename, 2 );

$filename_rand = implode( '.', array(
$file_parts[0],
mt_rand( 10000, 99999 ),
$file_parts[1],
) );

echo $filename_rand; // filename.12345.png



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum