How to change Upload name

<?php $errors=array(); if(isset($_POST["submit"])) { $funame=preg_replace('/[^a-zA-Z0-9-_\.]/i',' ',cleanvalues2($_FILES["file"]["name"])); $dir="../upload/files/"; if($funame) { $frand=rand(0000, 9999); $funame=$frand.$funame; $size=$_FILES["file"]["size"]; ?>

the output will be this

963[Upload name].jar

eg. 963Opera.jar

but i want it to show like this

[upload name]-ST.jar

that -ST to be constant before the file type

Thanks In Advance.

Try this:
[php]<?php
$errors = array();
if (isset($POST[“submit”])) {
$file_clean = preg_replace(’/[^a-zA-Z0-9-
.]/i’,’ ',cleanvalues2($_FILES[“file”][“name”]));
$dir = “…/upload/files/”;
if ($funame) {
$frand = rand(0000, 9999);
$file_name = pathinfo($file_clean, PATHINFO_FILENAME);
$file_extension = pathinfo($file_clean, PATHINFO_EXTENSION);

	$funame = $file_name."-".$frand."-ST".$file_extension;
	$size = $_FILES["file"]["size"];

?>[/php]
$file_name grabs, strictly, the name of the file: [Upload name]
$file_extension grabs the file extension: .jar
$funame should now output: [Upload name]-963-ST.jar

You can use the script without the number generator, but then you have the issue of duplicating file names.
If you wish to remove it, just delete this from $funame:
[php]"-".$frand.[/php]

Let me know if you have any issues. Since I can’t test the script on my side, I have to eyeball any errors I made.

Sponsor our Newsletter | Privacy Policy | Terms of Service