<?php
class billed{
//$navn kommer til at indeholde enten $billede['navn'] eller
//det nye navn, man kan intaste og sætte ned setNavn($navn)
private $mappe, $billede, $navn;
public function __construct($mappe){
$this->mappe = $mappe;
}
public function setBillede($files){
$this->billede=$files;
//for at sikre, at $navn har en værdi også selvom man ikke
//har givet nyt navn
$this->navn= $files['name'];
return $this->navn;
}
//kald inden upload hvis du vil ændre filnavn
public function setNavn($navn){
//finder filtype udfra det oprindelige billede
$array = explode(".",$this->billede['name']);
$plads = count($array)-1;
$filtype = $array[$plads];
$this->navn = $navn.".".$filtype;
}
//ændrer til $this-> navn for at at få det rigtige billednavn med, uanset
//om det oprindelige filnavn skal bruges eller et nyt navn er sat
//med setNavn($navn)
public function upload(){
if ($this->billede != ""){
$this->navn = time() . "_" . $this->navn;
copy($this->billede['tmp_name'], $this->mappe.$this->navn);
return $this->navn;
}else {
return false;
}
}
public function form(){
if ($_FILES['billed']['tmp_name'] != ""){
//for at sikre at $this->navn altid har værdig
$this->billede=$_FILES['billed'];
$this->navn = $_FILES['billed']['name'];
}else {
$tekst = '<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="billed"><br />
<input type="submit">
</form>';
return $tekst;
}
}
//kan bruges til at vise netop uploadede billede
//eller til at vise et andet billede
public function visBillede($navn = NULL){
if (!$navn){
$url = $this->mappe.$this->navn;
}else {$url = $navn;}
return "<img src='".$url."'/>'";
}
}
?>
/***************************************************************/
<?php
class Database{
private $dbconnect, $database, $resulte, $data, $numRows, $pointer;
function __construct(){
$this-> dbconnect = mysql_connect('localhost','pia.wi11.ots.dk','091173');//connecter til databasen
$this-> database = mysql_select_db("pia_wi11_ots_dk");//navnet på databasen
}
public function select($table, $orderby='id'){
//selecter fra databasen(tabeller)
$this->resulte = mysql_query("SELECT * FROM $table ORDER BY $orderby");
$this->numRows=mysql_num_rows($this->resulte);
}
public function next(){
if($this->data=mysql_fetch_assoc($this->resulte)){
return true;
}else{
return false;
}
}
//trækker ud fra tabellen
public function fetch($kolonne){
return $this->data[$kolonne];
}
// Almene sql funktioner
public function count(){
return mysql_num_rows($this->result);
}
public function delete($navn, $where){
mysql_query("DELETE FROM $navn WHERE $where");
}
public function insert($table, $orderby='id' ){
$sql = "INSERT INTO $table ORDER BY LIMIT 3";
mysql_query($sql);
}
public function update($navn, $value, $where){
$sql = "UPDATE $navn SET $value WHERE $where";
mysql_query($sql);
}
//datagrib
public function getDataGrib(){
if (isset($_POST['pointer'])){
if (isset($_POST['forrige'])){
$this->setPointer($_POST['pointer'] - 1);
$this->seekBackward();
}
if (isset($_POST['naeste'])){
$this->setPointer($_POST['pointer'] + 1);
$this->seekForward();
}
}else {
$this->next();
}
$tekst = "<table cellpadding = '4' cellspacing = '0' border = '1'>";
$tekst .= "<tr bgcolor='yellow'><th>Feltnavn</th><th>Værdi</th></tr>";
$i = 0;
foreach ($this->data as $key => $value){
$i++;
$tekst .= "<tr";
if ($i%2)
$tekst .= " bgcolor ='lightgrey'";
$tekst .= "><td>$key</td><td>$value</td></tr>";
}
$tekst .="</table>";
if (mysql_num_rows($this->resulte) > 1){
$tekst .= "<form action='' method='POST'>
<input type='submit' name='forrige' value='<--'>
<input type='submit' name='naeste' value='-->'>
<input type='hidden' name='pointer' value='$this->pointer'>
</form>";
}
return $tekst;
}
private function setPointer($pointer){
$this->pointer = $pointer;
}
private function seekForward(){
if ($this->pointer >= mysql_num_rows($this->resulte)){
$this->setPointer(0);
}
mysql_data_seek($this->resulte, $this->pointer);
$this->next();
}
private function seekBackward(){
if ($this->pointer < 0){
$this->setPointer(mysql_num_rows($this->resulte) -1);
}
mysql_data_seek($this->resulte, $this->pointer);
$this->next();
}
}
?>
/**************************************************************/
//Her skal jeg hente fra databasen//
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Language" content="da" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Forsiden</title>
</head>
<body>
<div id="ph">
<div id="text"><img src="image/pp.jpg"/></div>
<hr></hr>
<div id="banner"><div id="boks"></div></div>
<hr></hr>
<!-- laves i database -->
<?php
include 'admin/class.db.php';
include 'admin/class.billed.php';
$db = new Database();
$db->select('people_news');
while($db->next()){
echo "<div id='overskrift'>";
echo "<p class='overskrift'>";
echo "<b>";
echo $db->fetch('overskrift');
echo "</b>";
echo "</p>";
echo "</div>";
echo "<div id='block'>";
echo "<div id billed>";
echo "<img src='$db->fetch[sti]'>";
echo "</div>";
echo "<div id='reklame'>";
echo "<img src='image/minotaur250.jpg'/>";
echo "</div>";
echo "</div>";
echo "<hr>";
echo "</hr>";
}
?>
<!-- database slut -->
<h1></h1>
<div id="overskrift">
<form method="get" action="" class="form">
<p class="search"><b>Search our database of Galleries:</b> </p>
<input id="search-text" type="text" name="s" value="Search" size="15" />
<input type="submit" id="search-submit" value="Go!" />
</form>
<p class="or"><b>OR</b> <a href="">View our entire list</a></p>
</div>
</div>
</body>
</html>
/**************************************************************/
//her skal jeg sætte ind i databasen//
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Language" content="da" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style1.css" rel="stylesheet" type="text/css" />
<title>admin forsiden</title>
</head>
<body>
<div id="ph">
<div id="text"><img src="image/pp.jpg"/></div>
<hr></hr>
<div id="banner"><div id="boks"></div></div>
<hr></hr>
<!-- laves i database -->
<div id="overskrift"><p class="overskrift"><b>CELEBRITY PROFILE - 50 Cent</b></p></div>
<div id="block">
<!-- <div id="billed"></div> -->
<div id="reklame"><img src="image/minotaur250.jpg"/></div>
</div>
<?php
include 'class.db.php';
include 'class.billed.php';
$db = new Database();
//$db->insert('people_news');
$db->fetch['dato'];
$db->fetch['overskrift'];
$db->fetch['sti'];
if (!empty($_FILES['billedfil']['name'])){
$files = $_FILES['billedfil'];
$nytnavn = $_POST['nytnavn'];
$billede = new billed("billeder/");
$billede->setBillede($files);
if ($nytnavn != ""){
$billede->setNavn($nytnavn);
}
$filnavn_inc_timestamp = $billede->upload();
if ($filnavn_inc_timestamp){
//nu kan $filnavn_incl_timestamp gemmes i database
}
echo $billede->visBillede();
}
?>
<div id="form">
<form action="code_insert.php" method="post" enctype="multipart/form-data">
<div id="fil">Dato: <input class="felt" type="text" name="dato" value="<?php echo $db->fetch['dato'];?>"/></div>
<div id="fil">Profile: <input class="felt" type="text" name="text" value="<?php echo $db->fetch['overskrift'];?>"/></div>
<div id="bill"><img src="billeder/<?php echo $db->fetch['sti'];?>"/></div>
<div id="fil">Fil: <input class="felt" type="file" name="billede"/></div>
<input type="hidden" name="id" value="<?php echo $db->fetch['id'];?>"/>
<input class="knap" type="submit" value="SÆT IND"/>
</form>
</div>
<!-- database slut -->
<h1></h1>
<div id="overskrift">
<form method="get" action="" class="form">
<p class="search"><b>Search our database of Galleries:</b> </p>
<input id="search-text" type="text" name="s" value="Search" size="15" />
<input type="submit" id="search-submit" value="Go!" />
</form>
<p class="or"><b>OR</b> <a href="">View our entire list</a></p>
</div>
</div>
</body>
</html>
/***************************************************************/
//her er en code_insert.php som jeg ikke ved om jeg skal brug//
<?php
include 'class.db.php';
include ("class.billed.php");
$db = new Database();
$db->insert ('people_news');
$overskrift = $_POST ['overskrift'];
$dato = time ();
$sti = $_POST['sti'];
$mitBillede = new billed ( "image2/" );
//print_r($_FILES['billede']);
if ($_FILES [billede] [error] == 0) {
$mitBillede->setBillede ( $_FILES ['billede'] );
$nytBillede = $mitBillede->upload ();
if ($nytBillede != "") {
//$mitBillede->lavProportionalThumb($nytBillede);
//$mitBillede->lavThumb($nytBillede);
}
}
$sql = "INSERT INTO people_news (dato, overskrift, sti) VALUES ('$dato','$overskrift','$sti')";
$result = mysql_query ( $sql ) or die ( 'FEJL:' . mysql_error() );
//header("location:forside.php?$db->fetch['sti']");
?>
//jeg kan få (dato, overskrift) ned fra databasen men ikke mit billede(sti)og kan inten få lagt op. håber dette er bare lidt overskueligt for//