Sari la conținut
Forum Roportal
RHS

Rename file to upload

Evaluează acest topic

Postări Recomandate

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:

<?php

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">

<br><br>

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

<br><br>

<div align="center">

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

<tr>

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

html;

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

</td>

</tr>

</table>

</div></body>

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].");

$type=strtolower($type);

//file with the upload folder

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

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

}

else {

echo "Invalid file format";

exit();

}

$userjpg="userdata/$actualuser/".".jpg";

$usergif="userdata/$actualuser/".".gif";

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

unlink($usergif);

}

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

unlink($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

$_uploaded=1;

}

else

{

//error uploading

$_error=1;

}

}

else

{

$_check=$_check+1;

}

 

}

 

//file(s) did upload

if($_uploaded == '1')

{

$_uploaded=0;

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')

{

$_error=0;

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)

{

$_check=0;

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

}

}

?>

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

Partajează acest post


Link spre post
Distribuie pe alte site-uri

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum

×