- Joined
- Jan 9, 2011
- Messages
- 9
- Reaction score
- 7
Здравейте, за тази система ще са ви нужни 4 файла и 1 папка :
1 - SQL FILE
2 - Upload File / upload.php /
3 - Show uploaded files / files.php /
4 - Setting file / setting.php /
5 - Folder Name / files /
----------------------------------------------------------------------------
1 - SQL FILE
----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `files` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`desc` varchar(255) collate utf8_unicode_ci NOT NULL,
`file` varchar(255) collate utf8_unicode_ci NOT NULL,
`expire` varchar(255) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
====================================
2 - Upload file name : *(upload.php)* =
====================================
<h3>Качване на файл</h3>
<form method='post' action='' enctype='multipart/form-data'>
<p>
<label>Описание</label>
<input type="text" name="desc" class="input" />
</p>
<p>
<label>Файл</label>
<input type="file" name="file" class="input" />
</p>
<p><input type="submit" class="submit" name="upload" value="Качи" /></p>
</form>
<?php
if($_POST['upload']) {
$desc = htmlspecialchars($_POST['desc']);
$expire = date("d.m.Y", strtotime("+7 days"));
$file = $_FILES['file'];
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$format = end(explode(".", $name));
if($format != "png" && $format != "gif" && $format != "jpeg" && $format != "jpg" && $format != "JPG" && $format != "PNG" && $format != "GIF" && $format != "js" && $format != "rar" && $format != "html" && $format != "zip") {
echo "Вие сте избрали файл с непозволен формат!<br />Позволени формати:<br /><b>.zip</b>, <b>.html</b>, <b>.js</b>, <b>.png</b>, <b>.gif</b>, <b>.jpg/jpeg</b> и <b>.rar</b>";
} else {
$string = "0123456789qwertyuiopasdfghjklzxcvbnm";
$new_string = str_shuffle($string);
$location = "files/$new_string.$format";
move_uploaded_file($tmp_name, $location);
$run_q = mysql_query("INSERT INTO files VALUES ('', '$name', '$desc', '$location', '$expire')") or die(mysql_error());
echo "Файла е успешно качен!<br />Линк
<input type='text' value='http://YOURWEBSITE/$location' />";
}
}
?>
==========================================
3 - Show Uploaded Files name : *(files.php)* =
==========================================
<h3>Всички файлове</h3>
<?php
$runq = mysql_query("SELECT * FROM `files` ORDER BY id DESC") or die (mysql_error());
while($row = mysql_fetch_assoc($runq)) {
echo '<div style="margin-left: 5px; border: 1px solid gray; padding: 2px 4px 2px 4px; float: left;"> <a href="'.$row['file'].'" title="'.$row['desc'].'"> '.$row['name'].' </a> </div><div style="clear: both;"></div>';
}
?>
=======================================
4 - Setting Files name : *(setting.php)* =
=======================================
<?php
$host = "YOURHOST";
$user = "USERNAME";
$password = "PASSWORD";
$db = "YOURDB";
$connect = mysql_connect($host, $user, $password);
mysql_select_db($db,$connect) or die (mysql_error());
?>
1 - SQL FILE
2 - Upload File / upload.php /
3 - Show uploaded files / files.php /
4 - Setting file / setting.php /
5 - Folder Name / files /
----------------------------------------------------------------------------
1 - SQL FILE
----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `files` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`desc` varchar(255) collate utf8_unicode_ci NOT NULL,
`file` varchar(255) collate utf8_unicode_ci NOT NULL,
`expire` varchar(255) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
====================================
2 - Upload file name : *(upload.php)* =
====================================
<h3>Качване на файл</h3>
<form method='post' action='' enctype='multipart/form-data'>
<p>
<label>Описание</label>
<input type="text" name="desc" class="input" />
</p>
<p>
<label>Файл</label>
<input type="file" name="file" class="input" />
</p>
<p><input type="submit" class="submit" name="upload" value="Качи" /></p>
</form>
<?php
if($_POST['upload']) {
$desc = htmlspecialchars($_POST['desc']);
$expire = date("d.m.Y", strtotime("+7 days"));
$file = $_FILES['file'];
$tmp_name = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$format = end(explode(".", $name));
if($format != "png" && $format != "gif" && $format != "jpeg" && $format != "jpg" && $format != "JPG" && $format != "PNG" && $format != "GIF" && $format != "js" && $format != "rar" && $format != "html" && $format != "zip") {
echo "Вие сте избрали файл с непозволен формат!<br />Позволени формати:<br /><b>.zip</b>, <b>.html</b>, <b>.js</b>, <b>.png</b>, <b>.gif</b>, <b>.jpg/jpeg</b> и <b>.rar</b>";
} else {
$string = "0123456789qwertyuiopasdfghjklzxcvbnm";
$new_string = str_shuffle($string);
$location = "files/$new_string.$format";
move_uploaded_file($tmp_name, $location);
$run_q = mysql_query("INSERT INTO files VALUES ('', '$name', '$desc', '$location', '$expire')") or die(mysql_error());
echo "Файла е успешно качен!<br />Линк
<input type='text' value='http://YOURWEBSITE/$location' />";
}
}
?>
==========================================
3 - Show Uploaded Files name : *(files.php)* =
==========================================
<h3>Всички файлове</h3>
<?php
$runq = mysql_query("SELECT * FROM `files` ORDER BY id DESC") or die (mysql_error());
while($row = mysql_fetch_assoc($runq)) {
echo '<div style="margin-left: 5px; border: 1px solid gray; padding: 2px 4px 2px 4px; float: left;"> <a href="'.$row['file'].'" title="'.$row['desc'].'"> '.$row['name'].' </a> </div><div style="clear: both;"></div>';
}
?>
=======================================
4 - Setting Files name : *(setting.php)* =
=======================================
<?php
$host = "YOURHOST";
$user = "USERNAME";
$password = "PASSWORD";
$db = "YOURDB";
$connect = mysql_connect($host, $user, $password);
mysql_select_db($db,$connect) or die (mysql_error());
?>