hexthem4n
Account Closed
- Impact
- 2
I need the following code to put a random number onto the file name. Like say you upload image.jpg, I want it to be like 213image.jpg after its uploaded. So that I dont have to worry about people getting the re-name your image error. Any help would be awsome! Here is the code.
PHP:
<?
//set these variables-----------------------------------------------------------------
$path = "test/uploads/"; //path to your targetfolder after your domain
$max_size = 1000000; //maximum filesize
//optionally
$domain = $_SERVER["HTTP_HOST"]; //your domainname - change if necessary like "www.wza.be"
//------------------------------------------------------------------------------------
?>
<?
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) {
echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {
if (file_exists("../".$path . $HTTP_POST_FILES['userfile']['name'])) {
echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], "../".$path .$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else {
?>
<br>
<p> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>Find
your file here: </strong></font><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><strong><font color="#990000"><a href="http://<? echo $domain; ?>/<? echo "../".$path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
</a></font></strong><font color="#990000"><a href="http://<? echo $domain; ?>/<? echo "../".$path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><font color="#B6B66D">http://<? echo $domain; ?>/<? echo $path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?></font></a><strong><a href="http://<? echo $domain; ?>/<? echo "../".$path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>" target="_blank"><br>
</a></strong></font><br>
<strong><font color="#FFFFFF">HTML:</font></strong><br>
<font color="#B6B66D"><img src="http://<? echo $domain; ?>/<? echo $path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>"></font><br>
<br>
<font color="#FFFFFF"><strong>BBCode: </strong><strong></strong></font><font color="#990000"><strong><br>
</strong> <font color="#B6B66D">[img]http://<? echo $domain; ?>/<? echo $path; ?><? echo $HTTP_POST_FILES['userfile']['name']; ?>[/img]</font></font></font></p>
<?
}
echo "<font color=\"#B6B66D\" face=\"Geneva, Arial, Helvetica, sans-serif\"><hr>";
echo "Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
echo "</font>";
}
}
?>







