sniped22 Posted February 28, 2007 Share Posted February 28, 2007 On one page, an upload box. This page uploads the image and generates info on profile.php. <?php function createRandomUrl() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 15) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } function createRandomPic() { $chard = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 5) { $num = rand() % 33; $tmp = substr($chard, $num, 1); $pic = $pic . $tmp; $i++; } return $pic; } $file = $_FILES["file"]["name"]; $password = createRandomUrl(); echo "Your link is: http://localhost/nextsite/upload/".$password.".html"; echo '<br>'; $new_page = "upload/".$password.".html"; $somecontent = '<html> <body> <img src="../upload/'.$file.'"> </body> </html>'; $handle = fopen($new_page, 'w'); fwrite($handle, $somecontent); fclose($handle); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Your hotlink for forums is: [url]http://localhost/nextsite/upload/".$password.".html[/url]"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); ?> how can I rename the uploaded image to its current file name along with another random string at the end. For example, i upload a.bmp, I want the file to be renamed to a1b5.bmp Any help? Thanks Link to comment https://forums.phpfreaks.com/topic/40459-renaming-uploaded-picture/ Share on other sites More sharing options...
itsmeArry Posted February 28, 2007 Share Posted February 28, 2007 $arrName = explode(".", $_FILES["fie1"]["name"]); $name = $arrName[0].rand(1,9); $ext = $arrName[1]; $newName = $name.".".$ext; $destination = $newName; then use move_uploaded_file ( $_FILES["fie1"]["tmp_name"], $destnation) Link to comment https://forums.phpfreaks.com/topic/40459-renaming-uploaded-picture/#findComment-195872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.