Upload скрипт на картинки!

C++ JAVA
User avatar
LiSicHkA
Турист
Турист
Posts: 312
Joined: Thu Oct 22, 2009 6:50 pm
Contact:

Upload скрипт на картинки!

Post by LiSicHkA » Fri Apr 09, 2010 7:06 am

Дайте ми 1 ъплоуд скрипт за картинки, който да добавя в моя сайт? Благодаря предварително :)

User avatar
bankera1990
Потребител
Потребител
Posts: 683
Joined: Sat Aug 01, 2009 2:28 am
Answers: 15

Post by bankera1990 » Fri Apr 09, 2010 7:25 am

искаш да съхранява картинките в папка или с линк :)

User avatar
teroristd
Много Редовен
Много Редовен
Posts: 1769
Joined: Thu Feb 18, 2010 11:50 am
Answers: 83

Post by teroristd » Fri Apr 09, 2010 7:44 am

Надявам се да не съм объркал нещо :) и трябва да си направиш папка Upload

config.php

<?php
$db_conn = @mysql_connect("localhost", "root", "parolata") or die(mysql_error()); // тук си пишете данните за връзка с MySQL
@mysql_select_db("news", $db_conn) or die(mysql_error()); // тук ви е връзкта с базата данни.
mysql_query("SET NAMES cp1251");

$exp_pic = array("jpg","png","gif","jpeg"); // разширения за картинката
$max_size_pic = 10000; // запишете максималния размер на картинката(в KB)
$file_copy = "Upload/"; // къде да се записват файловете


$max_width_pic = 140; // максимална ширина на картинката
$max_height_pic = 140; // максимална височина на картинката




?>

upload.php




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Upload</title>
</head>
<body>
<?php
include "config.php";



if ($_POST['submit'])
{

if($_FILES['pic']['name']){
$file_ext = strtolower(substr($_FILES[pic][name],strrpos($_FILES[pic][name],".")));
$new_name_pic="$file_copy".new_name($exp)."$file_ext";
while (file_exists($new_name_pic)) {$new_name_pic="$file_copy".new_name($exp)."$file_ext";}
@move_uploaded_file($_FILES['pic']['tmp_name'],$new_name_pic);
}

if($_FILES['pic1']['name']){
$file_ext1 = strtolower(substr($_FILES[pic1][name],strrpos($_FILES[pic1][name],".")));
$new_name_pic1="$file_copy".new_name($exp)."$file_ext1";
while (file_exists($new_name_pic1)) {$new_name_pic1="$file_copy".new_name($exp)."$file_ext1";}
@move_uploaded_file($_FILES['pic1']['tmp_name'],$new_name_pic1);
}

if($_FILES['pic']['name'] && $_FILES['pic1']['name'] ) {
$sql = mysql_query("INSERT INTO `tablicata` (`pic`,`pic1`) VALUES ('$new_name_pic','$new_name_pic1');

echo "<a href='index.php' style = 'position:absolute; top:0px; left:400px;'>Начало.</a>";

}

else{

echo"<p style='color:red;'>Моля попълнете всички полета.</p>";
}

}

?>


<form action="" enctype="multipart/form-data" method="post">
<table border="0">

<tr><td>Главна снимка:<b style="color:red;"> *</b></td><td><input type="file" name="pic"></td></tr>
<tr><td>Снимка 1 :<b style="color:red;"> *</b></td><td><input type="file" name="pic1"></td></tr>

</table>
<input type="submit" name="submit" value="Добави">
</form>

</body>
</html>

darknezz_zone
Нов
Нов
Posts: 42
Joined: Tue Mar 16, 2010 5:41 am
Contact:

Post by darknezz_zone » Fri Apr 09, 2010 7:55 am

Aми аз искам също. Искам да се качва от комютър и да поддържа всички формати снимки(gif,jpeg,png). И автоматично да дава bbcodes към снимката.
Но да е без описание или пък заглавие. Без галерия без нищо. Само снимката да се качва от компютър и да излизат главният линк и ббкодовете.

Мерси предварително

User avatar
LiSicHkA
Турист
Турист
Posts: 312
Joined: Thu Oct 22, 2009 6:50 pm
Contact:

Post by LiSicHkA » Fri Apr 09, 2010 7:56 am

Направи я със проверките :)

Karcho
Потребител
Потребител
Posts: 1405
Joined: Wed Apr 07, 2010 4:40 pm
Answers: 155

Post by Karcho » Fri Apr 09, 2010 8:04 am


User avatar
bankera1990
Потребител
Потребител
Posts: 683
Joined: Sat Aug 01, 2009 2:28 am
Answers: 15

Post by bankera1990 » Fri Apr 09, 2010 8:43 am

:) доста яко клипче :?: ще ми свърши добра работа

: Ах този досаден Скайп :D

ragouster
Нов
Нов
Posts: 80
Joined: Tue Oct 13, 2009 10:31 am

Upload

Post by ragouster » Fri Apr 09, 2010 9:14 am

upload.php
<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 2000000;

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array('.zip','.jpg','.png','.gif','.doc','.jpeg');

//Allow file delete? no, if only allow upload only
$DELETABLE = true;


//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/************************************************************
* Setup variables
************************************************************/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "твоята директория";
$upload_url = $url_dir."твоята директория";
$message ="";

/************************************************************
* Create Upload Directory
************************************************************/
if (!is_dir("files")) {
if (!mkdir($upload_dir))
die ("upload_files directory doesn't exist and creation failed");
if (!chmod($upload_dir,0755))
die ("change permission to 755 failed.");
}

/************************************************************
* Process User's Request
************************************************************/
if ($_REQUEST[del] && $DELETABLE) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
fclose($resource);

if (strpos($_REQUEST[del],"/.")>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print "<script>window.location.href='$url_this?message=deleted successfully'</script>";
}
}
else if ($_FILES['userfile']) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
.$_FILES['userfile']['name']." "
.$_FILES['userfile']['type']."\n");
fclose($resource);

$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url);

print "<script>window.location.href='$url_this?message=$message'</script>";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";

/************************************************************
* List Files
************************************************************/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "<a href='$upload_dir$file'>".$file."</a> - URL: <b>$upload_url$file</b>";
if ($DELETABLE)

$filelist .= " Added at ".date("d-m H:i", filemtime($upload_dir.$file))
."";
$filelist .= " <a style='text-decoration:none; font-weight:bold' href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
$filelist .="<br>";
}
}

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\\","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;

//File Name Check
if ( $file_name =="") {
$message = "Грешен файл, разрешените формати са:'.jpg','.png','.gif','.jpeg'";
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name е качен успешно." :
"Something is wrong with uploading the file.";
return $message;
}

?>


<html>
<head>
<title>Simple uploader</title>
<link rel=stylesheet href=style.css>
</head>
<body>
<br><br>
<center>

<br>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Качи снимка <input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Качи">
</form>

style.css
body {
background: transparent ;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
* {
font-family:Verdana;
font-size:10px;
}

a:link {
color: #990000;
text-decoration: none;
font-weight: bold;
}
a:visited {
color: #990000;
text-decoration: none;
font-weight: bold;
}

<br><b><u><font color=red><?=$_REQUEST[message]?></font> </b></u><br><br>

<a style="text-decoration:none" href="http://imaloednovreme.com">Bate Zarko</a>
</sup></small>
</center>
Last edited by ragouster on Fri Apr 09, 2010 4:06 pm, edited 1 time in total.

baso
Потребител
Потребител
Posts: 789
Joined: Thu Apr 01, 2010 5:54 pm
Answers: 72
Location: Пазарджик
Contact:

Post by baso » Fri Apr 09, 2010 2:02 pm

Добър ден,

ще дам един скрипт, който писах за един потребител :)

add.php

Code: Select all

 <center>
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="plugin" /> <br />
<input type="submit" name="submit" value="Добави" /> <br />
<?php
include "conf.php";
if&#40;$_POST&#91;'submit'&#93;&#41; &#123;
$tmp_name = $_FILES&#91;'plugin'&#93;&#91;'tmp_name'&#93;;
$filename = $_FILES&#91;'plugin'&#93;&#91;'name'&#93;;
$format = end&#40;explode&#40;".", $filename&#41;&#41;;
if&#40;$format != "jpg, gif, png"&#41; &#123;
echo "Формата, който сте избрали е непозволен!";
&#125;
else &#123;
$link = 'images/'.$filename.'';
move_uploaded_file&#40;$tmp_name, $link&#41;;
$sql = 'INSERT INTO `pictures` &#40;`link`&#41; VALUES &#40;"'.addslashes&#40;$link&#41;.'"&#41;';
$rs = mysql_query&#40;$sql&#41; or die &#40;mysql_error&#40;&#41;&#41;;

echo 'Картинката беше качено успешно!';

&#125;
&#125;

?>



conf.php

Code: Select all

<?php
$host = "Хост";
$user = "Потребител";
$pass = "Парола ";
$db = "База от дани";
mysql_connect&#40;"$host","$user","$pass"&#41; or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"$db"&#41; or die&#40;mysql_error&#40;&#41;&#41;;
?>


view.php

Code: Select all

<?php
include "conf.php";
echo "<table><tr>";
$a = mysql_query&#40;"SELECT * FROM `pictures`  ORDER by id DESC"&#41; or die&#40;mysql_error&#40;&#41;&#41;;
while &#40;$r = mysql_fetch_array&#40;$a&#41;&#41;
&#123;
$url = $r&#91;'link'&#93;;
echo '<td><img src="$url" ></td>';
$i++;
if &#40;$i == 5&#41; &#123;$i = 0; echo "</tr><tr>"; &#125; else &#123; &#125;
&#125;
echo "</tr></table>";
?>


ето и сяла надявам се да ти помогне :)

Code: Select all

 CREATE TABLE `pictures` &#40;
`id` int&#40;11&#41; NOT NULL auto_increment,
`link` varchar&#40;255&#41; collate latin1_general_ci NOT NULL,
PRIMARY KEY  &#40;`id`&#41;
&#41; ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
със съдействието на @ proba

Само да ти кажа че трябва да създадеш една папка images :)
Last edited by baso on Fri Apr 09, 2010 2:07 pm, edited 1 time in total.

User avatar
kulov
Потребител
Потребител
Posts: 1156
Joined: Sat Apr 03, 2010 1:08 pm
Answers: 133

Post by kulov » Fri Apr 09, 2010 2:06 pm

Ето ти една много простичка, прави си проверки и всичко, само създай една папка images в която да се качват картинките, и ето я и нея :

index.php


Code: Select all




<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="upload_img.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> 

upload_img.php

Code: Select all



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<a href="index.php">Начало</a> <br /><br />

<?php
# Името на сайта, или линка &#58;&#41;
define&#40;LOCATION,"http&#58;//localhost/"&#41;;

# Папката в която да отиват снимките.
$folder = "images/";

# Размери когато качената снимка, е по-голяма в дължина/широчина
 # от показаните по долу.
 
$width_img_default   = "600";
$height_img_default  = "450";


# В какъв формат да се качват изображенията.
$open_type_upload = ".jpg";

# Различните типове на файловете, които са ни нужни
$file_name       =        $_FILES&#91;'file_name'&#93;&#91;'name'&#93;;
$file_tmp        =       $_FILES&#91;'file_name'&#93;&#91;'tmp_name'&#93;;
$file_size       =       $_FILES&#91;'file_name'&#93;&#91;'tmp_size'&#93;;
$file_type       =       $_FILES&#91;'file_name'&#93;&#91;'type'&#93;;


# Избиране на происволно име на файла.
$rand_file_name = rand&#40;1000000000, 9999999999999&#41;;

# Новото име на файла
$newfile_name = $rand_file_name.$file_name;


# Позволени типове файлове, които могат да се качват само.
$open_types = array&#40;
                     "image/jpg",
                     "image/jpeg",
                     "image/png",
                     "image/gif"
               &#41;;

               
# Aко формата, който качване не е позволен да
 # върне грешка в която да гласи, че има грешка
  # разбирасе ако и единствени възникне
   
if&#40;!in_array&#40;$file_type, $open_types&#41;&#41; &#123;
echo "Този формат файл не е позволен!";
&#125;
else &#123;

   

if &#40;file_exists&#40;$folder.$rand_file_name.$open_type_upload&#41;&#41; &#123;
echo "Този файл вече съществува. Моля опитайте отново!";
&#125;
else &#123;
   
// Самото качване на снимката
  $upload = move_uploaded_file&#40;$file_tmp, $folder.$rand_file_name.$open_type_upload&#41;;

 list&#40;$width_img, $height_img&#41; = getImagesize&#40;$folder.$rand_file_name.$open_type_upload&#41;;
 
 
 
# Показване на вече успешно качената картинка / снимка
if &#40;$upload == true&#41; &#123;


   if &#40;$width_img > $width_img_default || $height_img > $height_img_default&#41; &#123;     
   echo '<img src="'.$folder.$rand_file_name.$open_type_upload.'" width="'.$width_img_default.'" height="'.$height_img_default.'">';
   &#125;   
   else &#123;
   echo '<img src="'.$folder.$rand_file_name.$open_type_upload.'">';
   &#125;
   
   
echo '<br /><br /><br />';
echo 'Директен линк към изображението&#58; <br />';
echo '<input type="text" size="60" value="'.LOCATION.$folder.$rand_file_name.$open_type_upload.'">';
 
&#125;


&#125;
&#125;
?> 

Ами общо взето това е :)

Post Reply