• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Website Help

RunarM

Finally back
Joined
Jul 17, 2008
Messages
1,636
Reaction score
32
Location
Norway/Tromsø
NEW:
i want the picture to come up when you upload a picture, with a link..
Can anyone help me with it?



Yours, RunarM.
 
Last edited:
PHP:
<?
	echo '<?xml version="1.0" encoding="iso-8859-2"?>';
	$allowed_extensions = array('jpg', 'jpeg');
    $download_path = 'images/';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
		<title>
			Upload.com
		</title>
		<style>
			.error { color: red }
			a { color: gray; text-decoration: none }
			a:visited { color: gray; text-decoration: none }
			a:hover { color: gray; text-decoration: underline }
		</style>
	</head>
	<body>
		<div align="center">
			<a href="index.php">File list</a>
			<form enctype="multipart/form-data" action="upload.php" method="POST">
				<input type="hidden" name="MAX_FILE_SIZE" value=<?=$max_file_size?>/>
				<input name="file" type="file" size="40"/><br />
				<input type="submit" value="Send Your File"/>
			</form>
		<?
			$tmp_file = $_FILES['file']['tmp_name'];
			$name = $_FILES['file']['name'];
			$size = $_FILES['file']['size'];
			$extension = explode(".", $name);
			$ext = end($extension);
			
			if(is_uploaded_file($tmp_file)):
				if(!in_array($ext, $allowed_files)):
					echo '<span class="error">Not allowed extension.</span>';
					return true;
				endif;
				
				if($handle = opendir($download_path)):
					while(false !== ($file = readdir($handle))):
						if($name == $file):
							echo '<span class="error">File with that name is already on our server.</span>';
							return true;
						endif;
					endwhile;
				endif;
				move_uploaded_file($tmp_file, $download_path.''.$name);
				echo '<strong><a href="download.php?file='.$name.'">'.$name.'</a></strong> (<strong>'.size($size).'</strong>) has been succesfully uploaded.';
			endif;
		?>
		</div>
	</body>
</html>

Size function (by me pls is nob):
PHP:
	function size($size)
	{
		$size = $size;
		$s = 'b';
		
		if($size >= 1073741824):
			$size = $size / 1024 / 1024 / 1024;
			$s = 'gb';
		elseif($size >= 1048576):
			$size = $size / 1024 / 1024;
			$s = 'mb';
		elseif($size >= 1024):
			$size = $size / 1024;
			$s = 'kb';
		endif;
		
		return round($size, 2).' '.$s;
	}
 
Not allowed extension.'; return true; endif; if($handle = opendir($download_path)): while(false !== ($file = readdir($handle))): if($name == $file): echo 'File with that name is already on our server.'; return true; endif; endwhile; endif; move_uploaded_file($tmp_file, $download_path.''.$name); echo ''.$name.' ('.size($size).') has been succesfully uploaded.'; endif; ?>

Whats That oO
 
Whats That oO

What do you mean? :S
It checks if there is already a file with this name, you can implement random name generating and remove this warning.

Oh, and just noticed some error, rename $allowed_extensions to $allowed_files
 
This happens when i upload:

29900757.jpg


NEW:
'; $allowed_files = array('jpg', 'jpeg'); $download_path = 'images/'; ?>
 
Last edited:
Here, I fixed it for you, also added random string generator
PHP:
<?
    echo '<?xml version="1.0" encoding="iso-8859-2"?>';
    $allowed_extensions = array('jpg', 'jpeg');
    $download_path = 'images/';
	$max_file_size = 5242880;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
        <title>
            Upload.com
        </title>
        <style>
            .error { color: red }
            a { color: gray; text-decoration: none }
            a:visited { color: gray; text-decoration: none }
            a:hover { color: gray; text-decoration: underline }
        </style>
    </head>
    <body>
        <div align="center">
            <a href="index.php">File list</a>
            <form enctype="multipart/form-data" action="upload_.php" method="POST">
                <input type="hidden" name="MAX_FILE_SIZE" value=<?=$max_file_size?>/>
                <input name="file" type="file" size="40"/><br />
                <input type="submit" value="Send Your File"/>
            </form>
        <?
            $tmp_file = $_FILES['file']['tmp_name'];
            $name = $_FILES['file']['name'];
            $size = $_FILES['file']['size'];
            $extension = explode(".", $name);
            $ext = end($extension);
            
            if(is_uploaded_file($tmp_file)):
                if(!in_array($ext, $allowed_extensions)):
                    echo '<span class="error">Not allowed extension.</span>';
                    return true;
                endif;
                
				$newname = createName($ext);
                move_uploaded_file($tmp_file, $download_path.''.$newname);
                echo '<strong><a href="download.php?file='.$newname.'">'.$newname.'</a></strong> (<strong>'.size($size).'</strong>) has been succesfully uploaded.';
            endif;
			
			function createName($extension)
			{
				$length = 6;
				$pattern = 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
				$max = strlen($pattern) - 1;
				$random = '';
				mt_srand((double)microtime() * 1000000);
				for($i = 0; $i < $length; $i++)
					$random .= $pattern[mt_rand(0, $max)];
				
				return $random.'.'.$extension;
			}
			
			function size($size)
			{
				$size = $size;
				$s = 'b';
				
				if($size >= 1073741824):
					$size = $size / 1024 / 1024 / 1024;
					$s = 'gb';
				elseif($size >= 1048576):
					$size = $size / 1024 / 1024;
					$s = 'mb';
				elseif($size >= 1024):
					$size = $size / 1024;
					$s = 'kb';
				endif;
				
				return round($size, 2).' '.$s;
			}
        ?>
        </div>
    </body>
</html>

Make sure to name the file upload_.php, if you want to change it, change also here:
Code:
<form enctype="multipart/form-data" action="upload_.php" method="POST">
 
'; $allowed_extensions = array('jpg', 'jpeg'); $download_path = 'images/'; ?>
File list
/>

Not allowed extension.'; return true; endif; if($handle = opendir($download_path)): while(false !== ($file = readdir($handle))): if($name == $file): echo 'File with that name is already on our server.'; return true; endif; endwhile; endif; move_uploaded_file($tmp_file, $download_path.''.$name); echo ''.$name.' ('.size($size).') has been succesfully uploaded.'; endif; ?>

Umm... oO
 
Querido [CustomerName],

Estamos enviando este email para lembrar sobre seu pagamento

[InvoiceNo] gerada na data de [InvoiceDate] entre [DueDate].

Metodo de pagamento: [PaymentMethod]

Numero da compra: [InvoiceNo]
Preço: [AmountDue]
Data: [DueDate]

Você pode efetuar o pagamento no site OverAllGames - Locação de servidores

[Signature]
 
Querido [CustomerName],

Estamos enviando este email para lembrar sobre seu pagamento

[InvoiceNo] gerada na data de [InvoiceDate] entre [DueDate].

Metodo de pagamento: [PaymentMethod]

Numero da compra: [InvoiceNo]
Preço: [AmountDue]
Data: [DueDate]

Você pode efetuar o pagamento no site OverAllGames - Locação de servidores

[Signature]
WTF oO
 
Warning: move_uploaded_file(images/ycFs7P.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Documents and Settings\Rm\Skrivebord\Website\htdocs\upload.php on line 43

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Documents and Settings\Rm\Skrivebord\Website\tmp\php6D.tmp' to 'images/ycFs7P.jpg' in C:\Documents and Settings\Rm\Skrivebord\Website\htdocs\upload.php on line 43
ycFs7P.jpg (242.54 kb) has been succesfully uploaded.

oO??
ycFs7P.jpg (242.54 kb) has been succesfully uploaded.
 
Make sure there is images folder. :eek:

Oh yeaa.. forgot that :p
Now i only got this:
'; $allowed_files = array('jpg', 'jpeg'); $download_path = 'Images/'; ?>
File list
/>

Not allowed extension.'; return true; endif; if($handle = opendir($download_path)): while(false !== ($file = readdir($handle))): if($name == $file): echo 'File with that name is already on our server.'; return true; endif; endwhile; endif; move_uploaded_file($tmp_file, $download_path.''.$name); echo ''.$name.' ('.size($size).') has been succesfully uploaded.'; endif; ?>

But i can still upload oO
 
Querido [CustomerName],

Estamos enviando este email para lembrar sobre seu pagamento

[InvoiceNo] gerada na data de [InvoiceDate] entre [DueDate].

Metodo de pagamento: [PaymentMethod]

Numero da compra: [InvoiceNo]
Preço: [AmountDue]
Data: [DueDate]

Você pode efetuar o pagamento no site OverAllGames - Locação de servidores

[Signature]

Warning?
 
Back
Top