Tu mam dva nejake, mali by byt funkcne...
Upload script
index.php píše:
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<table align="center" border="0" bordercolor="#cccccc" cellpadding="5" width="760">
<tbody>
<tr>
<td valign="top">
<form method="post" enctype="multipart/form-data" action="upload.php"><div align="center"><label><input name="radiobutton" type="hidden" value="radiobutton" checked></label><input name="userfile" type="file" size="30" value="Vyber"><br><br><input name="upload" type="submit" value="Upload"></div></form>
<input name="MAX_FILE_SIZE" value="3145728" type="hidden"><input name="refer" value="" type="hidden"><input name="brand" value="" type="hidden">
</td>
</tr>
</tbody>
</table>
</body>
</html>
upload.php píše:
<html>
<body>
<?php $domain = "http://localhost"; $max_size = 153600000000000000000000000000000000000; $max_size_mb = "1,5"; $tsize = "300"; $path = "images/"; $tpath = "thumbs/"; 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 Size 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">A File with that name exists, please rename your file.</font><br>\n"; exit; } $zufall = rand(123,999999); $fupl = "$zufall"; $res = copy($HTTP_POST_FILES['userfile']['tmp_name'], "./".$path .$fupl .$HTTP_POST_FILES['userfile']['name']); if (!$res) { echo "<font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">Upload Failed, please try again</font><br>\n"; exit; } else { $domst = ""; $drecks = "/"; $imgf = $fupl.$HTTP_POST_FILES['userfile']['name']; $thbf = $tpath.$imgf; $urlf = $domst .$domain .$drecks .$path .$imgf; function createthumb($name,$filename,$new_w,$new_h) { $system=explode('.',$name); if (preg_match('/jpg|jpeg|JPG/',$system[1])) { $src_img=imagecreatefromjpeg($name); } if (preg_match('/png|PNG/',$system[1])) { $src_img=imagecreatefrompng($name); } if (preg_match('/gif|GIF/',$system[1])) { $src_img=imagecreatefromgif($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } if (preg_match("/gif/",$system[1])) { imagegif($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } createthumb($path.$imgf,$tpath.$imgf,$tsize,$tsize); } } else { echo "Sorry we dont allow that file type.\n"; exit; } } ?>
<body>
<center>
<table border='0' bgcolor='white'>
<FORM action="nowhere" method="post">
<center>
<tr>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="760">
<tbody>
<tr>
<td>
<p><a href="<? echo $domain; ?>"><b>Upload</b></a> another image.</p>
<br>
<center><img src='<? echo $thbf ?>' border="0"></center>
<br>
<br>
<input name="thetext" type="text" id="thetext" style="width: 500px;" value="[url=<? echo $urlf; ?>][img]<?%20echo%20$domst.$domain.$drecks.$tpath.$imgf;%20?>[/img][/url]" size="70"> Thumbnail for forums
<br>
<input name="thetext" type="text" id="thetext" style="width: 500px;" value="
[img]<?%20echo%20$urlf;%20?>[/img]" size="70"> Hotlink for forums
<br>
<input name="thetext" type="text" id="thetext" style="width: 500px;" value="<? echo $urlf; ?>" size="70"> Direct link to image
</td>
</tr>
</tbody>
</table>
</body>
</html>
</tr>
</table>
</body>
</html>
Kód:
db.php
<?php
$server = "localhost";
$user = "root";
$password = "";
$db = "test";
mysql_connect($server, $user, $password) or die(mysql_error());
mysql_select_db("$db") or die(mysql_error());
/* CREATE TABLE upload (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
); */
?>
index.php
<form method="post" enctype="multipart/form-data" action="upload.php">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="200000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
upload.php
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include "db.php";
$query = "INSERT INTO upload (name, size, type, content ) " . "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
}
?>
download.php
<?php
if(isset($_GET['name']))
{
include "db.php";
$id = $_GET['name'];
$query = "SELECT name, type, size, content " . "FROM upload WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
exit;
}
?>