Hi I have this code that saves images. How can i make it so that instead of the original name it just randoms a number? so instead of "name.extension" it will be "randomnumber.extension" ? $tmp = download_url( $img ); preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $img, $matches); $newfn = str_replace(array("%2B", "%52", "%20", "%5"), "B", basename($matches[0])); $oofnm = basename($matches[0]); if($newfn != $oofnm) { $newfn2 = str_replace(array(".jpg", ".png", ".gif"), "", $newfn); $tmppath = pathinfo( $tmp ); // extract path parts $newpth = $tmppath['dirname'] . "/". $newfn2 . "." . $tmppath['extension']; rename($tmp, $newpth); // renames temp file on server $tmp = $newpth; } $file_array['name'] = $newfn; $file_array['tmp_name'] = $tmp; // If error storing temporarily, unlink if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; continue; } PHP:
okay but where? i cant for my life find where in the code i should do it because whatever i try breaks it.
Here is the function that genarate random string, I use it myself. function generateRand($length){ $rawSalt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $rawSalt = str_shuffle($rawSalt); return substr($rawSalt, 0, $length); } PHP: Okay now user it this way first paste above function at the bottom of the php page, then go to line 14 the are variable "$newfn2", you need to change its value. paste this code just below line 13. $newfn2 = generateRand(8); PHP: and I hope your problem will be fixed by above solution. If there is any query, please let me know.