all right.I updated my code.Still doesn't work!sorry I probably have made a stupid mistake or forgot something but can't understand what!:|
<?php
function random_bytes($number_of_bytes)
{
if (!$number_of_bytes)
{
trigger_error('Invalid number of bytes.', E_USER_WARNING);
return false;
}
$random_bytes = null;
if (function_exists('mcrypt_create_iv'))
{
$random_bytes = mcrypt_create_iv($number_of_bytes, MCRYPT_DEV_URANDOM);
}
elseif (function_exists('openssl_random_pseudo_bytes'))
{
$random_bytes = openssl_random_pseudo_bytes($number_of_bytes);
}
else
{
$random_bytes = @file_get_contents('/dev/urandom', false, null, 0, $number_of_bytes);
}
if ($random_bytes)
{
return $random_bytes;
}
else
{
trigger_error('Failed to generate random bytes.', E_USER_WARNING);
return false;
}
}
function random_hex_bytes($number_of_bytes)
{
return bin2hex(random_bytes($number_of_bytes));
}
function upload($file,$dest){
$a=explode('.', $file['name']);
$filename=$a[0];
$ext=$a[1];
$add=microtime();
if (file_exists($file['name'])) {
random_hex_bytes(16);
}
if(move_uploaded_file($file['tmp_name'],$dest.random_hex_bytes(16))){
echo 'File Uploaded';
}
print_r($file['name']);
}
echo random_hex_bytes(16);
?>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<?php
if($_FILES['picture']['name']){
upload($_FILES['picture'],'upload/');
}
?>
<form action="" method="post" enctype="multipart/form-data">
<table width="500" align="center">
<tr>
<td><input type="file" name="picture"></td>
</tr>
<tr>
<td><input type="submit" value="Upload" name="submit"></td>
</tr>
<tr>
<td><input type="hidden" name="form" value="1"></td>
</tr>
</table>
</form>
</body>
</html>