Ne leksioni e sotem do te shohim menyren e ngarkimit te nje imazhi.
Se pari do te krijojme nje tabele per ruajtjen e imazheve.
CREATE TABLE `images` (
`code` int(11) NOT NULL auto_increment,
`title` varchar(150) NOT NULL,
`path` varchar(200) NOT NULL,
`description` text,
`section` int(11) NOT NULL default '0',
`rendi` int(11) default NULL,
`active` int(11) NOT NULL default '1',
`attachedto` int(11) NOT NULL default '1',
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=169
Dosja ku do te ngarkohen imazhet duhet te jete me te drejta shkrimi
ne linux chmod 777
ne windows eveyone read,write access
Do te perdorim dy skedare.
SKEDARI 1 - newimg.php
<?php
require_once("start.php");
require_once("myconfig.php");
require_once("db.php");
require_once("kontrollo.php");
require_once("mylib.php");
if (!isset($_REQUEST["attachedto"]))
{
exit("attached to what ??");
}
$attachedto=$_REQUEST["attachedto"];
//echo $attachedto;
if (!isset($_REQUEST["id"]))
{
exit("section??");
}
$section=$_REQUEST["id"]; // if the doc will be attached to a section
$article=sectionarticle($section);
if ($attachedto==2) // if the doc will be attached to an article
{
$article=$section;
}
$category=articlecategory($article);
echo $article;
echo $category;
//kontroll nese eshte id me kuptim
?>
<html>
<head>
<title>ICT Studio</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/css1.css" type="text/css" rel="stylesheet" >
<link href="css/ict.css" type="text/css" rel="stylesheet">
<script language="JavaScript">
function validate()
{
if(document.myform.title.value==""){alert('Verini nje titull');return false;}
if (document.myform.rendi.value=="" || document.myform.rendi.value==isNaN){alert('Verini nje rend');return false;}
//if(document.myform.content.value==""){alert('Verini nje pershkrim');return false;}
//for(var i=0;i<3;i++)// ------nuk e njef myfiles[] si array-------
//if(document.myform.myfiles[i].value==""){alert('Verini figuren ' + i);return false;}
return true;
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="830" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="2"><?php include('koka.php'); ?></td>
</tr>
<tr>
<td colspan="2"><?php display_login_info(); ?></td>
</tr>
<tr>
<td width="250" valign="top">
<table width="90%">
<tr>
<td><span class="t12r">Content Categories</span> </td>
</tr>
<?php
$cond=" 1 ";
$order=" order by rendi ";
//$x=DisplayAsLinkUL("categories","code","id","name","content.php",$cond,$order);
$x=DisplayAsLinkEditable("categories","code","id","name","content.php","editcategory.php","deletecategorywarning.php",$cond,$order,"t12");
?>
<tr>
<td> </td>
</tr>
<tr>
<td><span class="t12">Content of:</span> <a href="content.php?id=<?php echo $article_category; ?>" class="t12r">
<br>
<?php echo categoryname($category); ?></a></td>
</tr>
<?php
$cond=" active= 1 and category='".$category."' ";
$order=" order by rendi ";
//$x=DisplayAsLinkDesActive("articles","code","id","title","article.php",$cond,$order,$article_code);
$x=DisplayAsLinkEditable("articles","code","id","title","article.php","editarticle.php","deletearticle.php",$cond,$order,"t12");
?>
<tr>
<td> </td>
</tr>
<tr>
<td><span class="t12">Content of: </span><span class="t10r"><a href="content.php?id=<?php echo $article_category; ?>" class="t12r"><br>
<?php echo categoryname($category); ?> /</a></span><span class="t10r">
<span class="t10r"><?php echo articlename($article); ?></span> </span></td>
</tr>
<?php
$cond=" active=1 and article='".$article."'";
$order=" order by rendi ";
//$x=DisplayAsLinkUL("sections","code","id","title","section.php",$cond,$order,"");
$x=DisplayAsLinkEditable("sections","code","id","title","section.php","editsection.php","deletesection.php",$cond,$order,"t12");
?>
</table>
</td>
<td valign="top" width="630">
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td width="480" valign="top" class="kuti">
<form name="myform" method='post' enctype='multipart/form-data' action="newimg1.php" onSubmit="return validate(); ">
<table width="100%" border="0" class="t12" cellpadding="10" >
<tr>
<td><span class="t10r"><a href="content.php?id=<?php echo $article_category; ?>" class="t12r"><?php echo categoryname($category); ?>
/</a></span><span class="t10r"> <span class="t10r"><?php echo articlename($article); ?><a href="content.php?id=<?php echo $article_category; ?>" class="t12r">/</a></span><span class="t10r">
<span class="t10r"><?php echo sectionname($section); ?></span></span>
</span>
<input type="hidden" name="section" value="<?php echo $section; ?>">
<input type="hidden" name="attachedto" value="<?php echo $attachedto; ?>">
</td>
</tr>
<tr>
<td>Title :
<input type="text" name="title" size="70" class="t12">
</td>
</tr>
<tr>
<td>Order
<input type="text" name="rendi" size="10" value="<?php echo GetOrder('docs','section',$section); ?>" class="t12">
<span class="t10">int used to order the display of the content
in the ascending order</span> </td>
</tr>
<tr>
<td height="15" align="right" class="t12or">
<div id="info1"></div>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" border="1">
<tr>
<td width="62%">Description<br> <textarea class="t12lh24" cols="60" rows="10" name="description"></textarea></td>
<td valign="top"> Upload the file<br>
<input type="file" name="myfiles[]"
onChange="document.getElementById('info1').innerHTML = this.value.substr(this.value.lastIndexOf('\\')+1,this.value.length-this.value.lastIndexOf('\\')); myform.title.value=this.value;" class="t12" >
<br>
</td>
</tr>
</table>
</td>
<tr>
<td valign="top" align="center"><input name="submit" type="submit" value="Save" class="t12r">
</td>
</tr>
<tr>
<td align="center">
<table width="100%">
<tr>
<th colspan="3" class="catsinside"> Images in this section
</th>
</tr>
<?php
$cond=" active=1 and attachedto=".$attachedto." and section='".$section."'";
$order=" order by rendi ";
$limit=" ";
$x=DisplayAsLinkKuti("images","code","id","title","title","path","title","3",$cond,$order,"",$limit);
// DisplayAsLinkKuti($TableName,$Kodi,$KodiLink,$AfishimiExpr,$Afishimi,$Imazhi,$Teksti,$url,$cond,$orderby,$selected,$limit)
?>
<?php
$cond=" active=1 and attachedto=".$attachedto." and section='".$section."'";
$order=" order by rendi ";
$x=DisplayAsLinkEditable("docs","code","id","title","doc.php","editdoc.php","deletedoc.php",$cond,$order,"t12");
?>
</table>
</td>
</tr>
<tr>
<td align="center"> <span class="t10">REMARK:As a defualt the
new added content is active. If you want to deactive ti you
need to use the edit view of the content</span></td>
</tr>
</table>
</form></td>
<td width="150" valign="top"> </td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2"><?php include('footer.php');?></td></tr>
</table>
</body>
</html>
dhe skedarin : SKEDARI 2 - newimg1.php
<?php
require_once("start.php");
require_once("myconfig.php");
require_once("db.php");
require_once("kontrollo.php");
require_once("mylib.php");
//category
if (!isset($_REQUEST["section"]))
{
exit("witch section??");
}
$section=$_REQUEST["section"];
//rendi
if (!isset($_REQUEST["rendi"]))
{
exit("rendi??");
}
$rendi=$_REQUEST["rendi"];
//title
if (!isset($_REQUEST["title"]))
{
exit("title??");
}
$title=$_REQUEST["title"];
//content
if (!isset($_REQUEST["description"]))
{
exit("description??");
}
$description=$_REQUEST["description"];
if (!isset($_REQUEST["attachedto"]))
{
exit("attachedto??");
}
$attachedto=$_REQUEST["attachedto"];
//ngarkojme dokumentat
$numoffile = 1;
// Fix path of your file to be uploaded, don't forget to CHMOD 777 to this folder
$file_dir = "..//images//";
$j=0;
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$j++;
}
}
}
//fund ngarkimi i dokumentave
$f1=$_FILES['myfiles']['name'][0];
/*
$f2=$_FILES['myfiles']['name'][1];
$f3=$_FILES['myfiles']['name'][2];
*/
$active=1; //artikulli eshte aktiv si default
$sql="
insert into images(title,path,description,section,rendi,attachedto)
values ('".$title."','".$f1."','".$description."',".$section.",".$rendi.",".$attachedto.")";
mysql_query($sql)
or die(mysql_error());
$url="content.php";
if ($attachedto==2) $url="article.php";
if ($attachedto==3) $url="section.php";
$the_new_doc=GetLastInsertID();
?>
<script language="JavaScript">
window.location="<?php echo $url ?>?id=<?php echo $section; ?>";
</script>