Jump to content
Forum Roportal
Sign in to follow this  

Rename file to upload

Rate this topic

Recommended Posts

Asi dori daca ma poate ajuta cineva sa imi modifice acest script...

Cand fac upload se redenumeste fisierul respectiv dupa numele userului. Daca userul este ADMIN atunci fisierul se va chema ADMIN.jpg sau zip sau rar, depinde ce fisier e si daca fac upload tot la un file .jpg atunci se sterge admin.jpg si se inlocuieste cu noua poza care se cheama la fel.

Asi vrea ca fiecare fisier uploadat sa isi pastreze numele. Eu nu am reusit sa fac nimic :tease:


include ('protect.php');

//edit this

$_max_file_size = '1000000000'; //file size in bytes.

$upload_dir = "userdata/$actualuser/"; //upload folder..chmod to 777

$_i = "1"; //number of files to upload at one time

$file_exists= array('.zip','.rar','.jpg','.gif','.png');

//end edit

echo <<<html

<body bgcolor="#EBEBEB">


<p align="center"><b><font size="5" color="#FF0000"><i>File Upload</i></font></b></p>


<div align="center">

<table border="1" width="40%" cellspacing="0" cellpadding="0" height="107" bgcolor="#D1D1D1">


<td width="100%" height="95" valign="middle">


echo "<b><font size='1'>Maximum file size : 1 GB</font><br><br>";

echo "<form enctype='multipart/form-data' action='?do=upload' method='post'>";

echo "<input type='hidden' name='MAX_FILE_SIZE' value='" . $_max_file_size , "'>";

echo "<font color='#FF0000'><center>Please select a file: <br>";

//show number of files to select

For($i=0; $i <= $_i-1;$i++)


echo "<input name='file" . $i . "' type='file'>  ";


echo "<input type='submit' value='Upload File'></center></font>";

echo "</form></b><p align='center'><b><font size='3' color='#FF0000'><a href='main.php'>Home</a></font></b></p>";

echo <<<html






if($_GET['do'] == 'upload')


//upload all the fields until done

For($i=0; $i <= $_i-1; $i++)


//create a random number

$_random = rand(1, 1000000);

//actual file name with the random number

$_file_name =basename($_FILES['file' . $i]['name']);

$actualfilename=basename($_FILES['file' . $i]['name']);

$type= explode('.',strrev($actualfilename));

$type= strrev("$type[0].");


//file with the upload folder

$target_path = $upload_dir.$actualuser."$type";

if (in_array($type,$file_exists)) {


else {

echo "Invalid file format";





if ($type='.jpg' and file_exists($usergif)) {



elseif ($type='.gif' and file_exists($userjpg)) {



//do not upload the 'left blank' fields

if(basename($_FILES['file' . $i]['name']) != '')



if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))


//uploaded successfuly





//error uploading











//file(s) did upload

if($_uploaded == '1')



echo "<b><center>Your file has been uploaded.</center></b>";

echo ("<META HTTP-EQUIV=Refresh CONTENT=\"3; URL=main.php\">");


//file uploaded?

if($_error == '1')



echo "<b>There was an error uploading some of the file(s), please try again! Maybe the file size. Maximum file size is 1 GB.<br></b>";


//user selected a file?

if($_check == $_i)



echo "<b>Select a file first than click 'Upload File'.<br></b>";




<p align="center"><b>Copyright

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this