Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
echo('Upload images:
<FORM ENCTYPE="multipart/form-data" ACTION="' . $PHP_SELF . '" METHOD="POST">
The file: <INPUT TYPE="file" NAME="userfile">
<INPUT TYPE="submit" VALUE="Upload">
</FORM>');
$path = "/var/www/html/img/"; //ot tuka si izbira6 kude da ti se zapazwat snimkite
$max_size = 20000; // ot tuk kolko kb e max za kartinka
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 "The file is too big<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 "The file already exists<br>n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>n"; exit; } else { echo "upload sucessful<br>n"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>n";
} else { echo "Wrong file type<br>n"; exit; }
}
$my_file = $HTTP_POST_FILES['userfile']['name'];
?>
<html> <head>
<title>Качи</title>
</head>
<body>
<form method="POST" enctype="multipart/form-data" action="">
<p><input type="file" name="snimka" size="20"></br>
<input type="submit" value="Качи" name="submit">
<input type="reset" value="Изтрий" name="reset"></p>
</form>
</body>
</html>
<?php
if($_POST['submit']){
$snimka = $_POST['snimka'];
$snimka = htmlspecialchars($snimka);
$snimka = strip_tags($snimka);
if($izberi == NULL){
echo'Не сте избрали снимка.';
}
else{
$insert = mysql_query("INSERT INTO `tablica`(izberi)VALUES('$izberi')")or die (mysql_error());
echo'Снимката е добавена успешно!';
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="add.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Ъплоудване на снимки</strong></td>
</tr>
<tr>
<td>избор на файл
<input name="file_name" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Качи!" /></td></tr>
</table>
</td>
</form>
</tr>
</table>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<a href="index.php">Начало</a> <br /><br />
<?
$user = "root";//дб име
$pass = "vratastena123";//дб парола
$db = "files";//дб
$host = "localhost";//хост
$connection = mysql_connect($host, $user, $pass) or die("Сайтът не може да се свърже към базата данни1");//свързваме се към базата данни
$db = mysql_select_db($db,$connection)or die("Сайтът не може да се свърже към базата данни2")
?>
<?php
# Името на сайта, или линка :)
define(LOCATION,"http://localhost/");
# Папката в която да отиват снимките.
$folder = "images/";
# Размери когато качената снимка, е по-голяма в дължина/широчина
# от показаните по долу.
$width_img_default = "600";
$height_img_default = "450";
# В какъв формат да се качват изображенията.
$open_type_upload = ".jpg";
# Различните типове на файловете, които са ни нужни
$file_name = $_FILES['file_name']['name'];
$file_tmp = $_FILES['file_name']['tmp_name'];
$file_size = $_FILES['file_name']['tmp_size'];
$file_type = $_FILES['file_name']['type'];
# Избиране на происволно име на файла.
$rand_file_name = rand(1000000000, 9999999999999);
# Новото име на файла
$newfile_name = $rand_file_name.$file_name;
# Позволени типове файлове, които могат да се качват само.
$open_types = array(
"image/jpg",
"image/jpeg",
"image/png",
"image/gif"
);
# Aко формата, който качване не е позволен да
# върне грешка в която да гласи, че има грешка
# разбирасе ако и единствени възникне
if(!in_array($file_type, $open_types)) {
echo "Този формат файл не е позволен!";
}
else {
if (file_exists($folder.$rand_file_name.$open_type_upload)) {
echo "Този файл вече съществува. Моля опитайте отново!";
}
else {
// Самото качване на снимката
$upload = move_uploaded_file($file_tmp, $folder.$rand_file_name.$open_type_upload);
list($width_img, $height_img) = getImagesize($folder.$rand_file_name.$open_type_upload);
# Показване на вече успешно качената картинка / снимка
if ($upload == true) {
if ($width_img > $width_img_default || $height_img > $height_img_default) {
echo '<img src="'.$folder.$rand_file_name.$open_type_upload.'" width="'.$width_img_default.'" height="'.$height_img_default.'">';
}
else {
echo '<img src="'.$folder.$rand_file_name.$open_type_upload.'">';
}
echo '<br /><br /><br />';
echo 'Директен линк към изображението: <br />';
echo '<input type="text" size="60" value="'.LOCATION.$folder.$rand_file_name.$open_type_upload.'"><br />';
echo 'Виж всички снимки <a href="view.php">Тук</a>';
}
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<a href="index.php">Начало</a> <br /><br />
<?
$user = "root";//дб име
$pass = "vratastena123";//дб парола
$db = "files";//дб
$host = "localhost";//хост
$connection = mysql_connect($host, $user, $pass) or die("Сайтът не може да се свърже към базата данни1");//свързваме се към базата данни
$db = mysql_select_db($db,$connection)or die("Сайтът не може да се свърже към базата данни2")
?>
<?
$query=mysql_query("SELECT * FROM `files` ORDER BY `id` DESC") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
$file=$row['file'];
echo "<img src='images/$file' height='150px' width='150px'><br />";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Upload</title>
</head>
<body>
<?php
require "config.php";
require "functions.php";
$error = '';
if (isset($_POST['submit']) && !empty($_FILES['pic']['name']) && !empty($_POST['subject']))
{
if (in_array(strtolower(end(explode(".", $_FILES['pic']['name']))), $exp_pic))
{
if ($_FILES['pic']['size'] > 0 && $_FILES['pic']['size'] <= ($max_size_pic * 1024))
{
$ex_pic = end(explode(".", $_FILES['pic']['name']));
$new_name_pic = new_name($ex_pic);
while (file_exists($file_copy.$new_name_pic)) { $new_name_pic = new_name($ex_pic); }
while (file_exists($file_copy.$new_name_file)) { $new_name_file = new_name($ex_file); }
if (@copy($_FILES['pic']['tmp_name'], $file_copy.$new_name_pic))
{
mysql_query("INSERT INTO `files` (`pic`,`file`,`subject`) VALUES ('".$file_copy.$new_name_pic."','".$file_copy.$new_name_file."','".htmlspecialchars($_POST['subject'])."')");
$error = "Файла беше качен успешно!";
}
else
{
$error = "Файла не беше качен!";
}
}
else
{
$error = "Картинката не трябва да превишава $max_size_pic KB!";
}
}
else
{
$error = "Позволени са само следните разширения за картинка: ".implode(",", $exp_pic);
}
}
?>
<b><u>Всички полета са задължителни!</u></b>
<form action="" enctype="multipart/form-data" method="post">
<table border="0">
<tr><td>Изберете картинка:</td><td><input type="file" name="pic"></td></tr>
<tr><td>Описание:</td><td><textarea name="subject" rows="5" cols="30"></textarea></td></tr>
</table>
<input type="submit" name="submit" value="Изпрати">
</form>
<b><?=$error?></b>
</body>
</html>