Jump to content

renaming uploaded picture


sniped22

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.