0

i have a code here that generates resized images but it generates a fixed name $url = 'destination.jpg'; so here is my code instead of generate a fixed name how can i change the image name to random numbers and letters. eg $url = 'wy3vu45.jpg'

if ($_POST) {

        if ($_FILES["file"]["error"] > 0) {
                $error = $_FILES["file"]["error"];
        } 
        else if (($_FILES["file"]["type"] == "image/gif") || 
        ($_FILES["file"]["type"] == "image/jpeg") || 
        ($_FILES["file"]["type"] == "image/png") || 
        ($_FILES["file"]["type"] == "image/pjpeg")) {

                $url = 'destination .jpg';

                $filename = compress_image($_FILES["file"]["tmp_name"], $url, 50);
                $buffer = file_get_contents($url);

                /* Force download dialog... */
                header("Content-Type: application/force-download");
                header("Content-Type: application/octet-stream");
                header("Content-Type: application/download");

        /* Don't allow caching... */
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

                /* Set data type, size and filename */
                header("Content-Type: application/octet-stream");
                header("Content-Transfer-Encoding: binary");
                header("Content-Length: " . strlen($buffer));
                header("Content-Disposition: attachment; filename=$url");

                /* Send our file... */
                echo $buffer;
        }else {
                $error = "Uploaded image should be jpg or gif or png";
        }
}
  • 2
    We are always glad to help and support new coders but ***you need to help yourself first. :-)*** After [**doing more research**](https://meta.stackoverflow.com/q/261592/1011527) if you have a problem **post what you've tried** with a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Jay Blanchard Feb 13 '18 at 14:15
  • Did you try `uniqid()`? – Sal00m Feb 13 '18 at 14:17
  • *How* random (true random or pseudo-random)? And does the string have to be unique? – CD001 Feb 13 '18 at 14:17

0 Answers0