Parsi Coders
اپلود فایل با نام رندم - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Web Development and Design (http://parsicoders.com/forumdisplay.php?fid=47)
+--- انجمن: PHP Forum (http://parsicoders.com/forumdisplay.php?fid=48)
+--- موضوع: اپلود فایل با نام رندم (/showthread.php?tid=2645)



اپلود فایل با نام رندم - امیر - 08-05-2012

درود:
دوستان بهتر هست برای کمی بالا بردن امنیت سایت زمانی که کد اپلود عکس رو مینویسیم کد های زیر رو هم وارد کنیم تا اسم عکس ما تغییر کنه .(خب این چه فایده ای داره ؟) این کار باعث میشه که کمی کار هکر ها سختر بشه و هنگام اپلود عکس شل دار با پیدا نکردن فایل عکس کمی کارشون سختر بشه . Big Grin


ابتدا یک فایل به نام xxx.html میسازیم . این کد هارو توش کپی میکنیم .
کد:
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>

سپس یک فایل به نام upload.php به وجود بیارین و کد های زیر رو توش کپی کنید .
کد:
<?php
//This function separates the extension from the rest of the file name and returns it
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}

//This applies the function to our file  
$ext = findexts ($_FILES['uploaded']['name']) ;

//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
$ran = rand () ;

//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
$ran2 = $ran.".";

//This assigns the subdirectory you want to save into... make sure it exists!
$target = "images/";

//This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file has been uploaded as ".$ran2.$ext;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>

با استفاده از این کد فایل ها نام رندم میگیرن این قابلیت بسیار مهم هست و تقریبا تمام cms ها این کد رو دارن .