Poslao: 24 Jul 2008 17:26
|
offline
- Pridružio: 18 Dec 2007
- Poruke: 95
|
Imam problem ne znam kako da mi cita pravu sliku iz pretrage kad kliknes na link za sliku iz pretrage udje u folder gde se nalaze sve slike evo koda:
<?php
print "<font >";
$filename= "counter.txt" ;
$fd = fopen ($filename , "r") or die ("Can't open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
echo "This page has been visited <b>$fstring</b> times<br>";
fclose($fd) ;
$fd = fopen ($filename , "w") or die ("Can't open $filename") ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fd , $fcounted ) ;
fclose($fd) ;
print "</font>";
//napravi promenljive sa kratkim imenima
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'Niste uneli nista u pretragu.<br>'.
'Molimo vas pokusajte ponovo.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('nemesis','ford','escort','automobili');
if (mysqli_connect_errno())
{
echo'Greska:Nismo u mogucnosti da se povezemo sa bazom.'.
'Molimo vas pokusajte ponovo kasnije.';
exit;
}
$query = "select * from automobili where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query) or die($db->error);
$num_results = $result->num_rows;
echo '<p>Nadjenih modela: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<p><strong>'.($i+1).'. Marka: ';
echo htmlspecialchars(stripslashes($row['marka']));
echo '<br>------------------------------------------';
echo '</strong><br /> Model: ';
echo stripslashes($row['model']);
echo '<br>------------------------------------------';
echo '<br />Godiste: ';
echo stripslashes($row['godiste']);
echo '<br>------------------------------------------';
ovo je taj deo:
print('<p><a href="upload/'.$newfile.'">Pogledaj poslat fajl</a></p>');
echo '<br />Cena: ';
echo stripslashes($row['cena']);
echo '<br>------------------------------------------';
echo '<br />Boja: ';
echo stripslashes($row['boja']);
echo '<br>------------------------------------------';
echo '<br />email: ';
print('<p><a href="mailto:'.($row['email']).'">'.($row['email']).'</a></p>');
echo '<br>------------------------------------------';
echo '<br>___________________________________________';
echo '</p>';
}
$result->free();
$db->close();
?>
evo i upisa:
<?php
$marka = $_POST['marka'];
$model = $_POST['model'];
$cena = $_POST['cena'];
$godiste = $_POST['godiste'];
$boja = $_POST['boja'];
$email = $_POST['email'];
$slike = $_FILES['slike']['name'];
if (!$marka || !$model || !$cena || !$godiste || !$boja || !$email || !$slike)
{
echo 'Niste uneli tražene podatke.<br>'.
'Molimo vas pokušajte ponovo.';
exit;
}
if(!get_magic_quotes_gpc())
{
$marka = addslashes($marka);
$model = addslashes($model);
$cena = doubleval($cena);
$godiste = addslashes($godiste);
$boja = addslashes($boja);
$email = addslashes($email);
$slike = addslashes(fread(fopen($target_path = "upload/", "r")));;
}
@ $db = new mysqli('nemesis','ford','escort','automobili');
if (mysqli_connect_errno())
{
echo 'Greska neuspesno povezivanje sa bazom.'.
'Molimo pokusajte ponovo.';
exit;
}
$query = "insert into automobili values
('".$marka."','".$model."','".$cena."','".$godiste."','".$boja."','".$email."','".$target_pa
th = "upload/"."')";
$result = $db->query($query);
if($result)
echo 'Podaci su uspesno unešeni.<br>';
$db->close();
print("$marka<br>");
print("$model<br>");
print("$cena<br>");
print("$godiste<br>");
print("$boja<br>");
print('<p><a href="mailto:'.$email.'">'.$email.'</a></p>');
print("<img align = 'right' src='upload/".basename( $_FILES['slike']['name'])."'>");
?>
<?php
$uploaded=0;
$utime=time();
$uday= date('d');
$umonth= date('m');
$uyear= date('y');
$udate=$umonth.$uday.$uyear;
echo "Date:".$udate."<br>";
echo "Time:".$utime."<br>";
$filename="a".$udate.$utime;
echo "Create a unique name for a new file from date and time.<br>";
echo "Filename::".$filename."<br>";
$target_path = "/";
$target_path = $target_path . basename( $_FILES['slike']['name']);
echo "Target_path::".$target_path."<br><br>";
$_FILES['slike']['tmp_name']; // temp file
$target_path = "upload/"; //for my pc
echo "Read original name of the uploaded file <br>";
$original_file = basename($_FILES['slike']['name']);
echo "Original file::".$original_file."<br><br>";
echo "Getting the extention the file extension <br>";
$pos = strpos($original_file,".",0);
$ext = trim(substr($original_file,$pos+1,strlen($original_file))," ");
echo "extension::".$ext."<br>";
echo "Assemble new file name and extension <br>";
$newfile = $filename . "." . $ext;
echo "New file name::".$newfile."<br><br>";
echo "Move the file to the final destination <br>";
$target_path = $target_path . basename($newfile);
echo "Target_path::".$target_path."<br><br>";
if(move_uploaded_file($_FILES['slike']['tmp_name'], $target_path)) {
$uploaded=1;
$message="Fajl je ". basename( $_FILES['slike']['name']). " uspesno poslat";
}
else
{
$message="Doslo je do greske prilikom slanja, molimo vas pokusajte ponovo!";
}
echo $message;
if($uploaded==1)
print('<p><a href="upload/'.$newfile.'">Pogledaj poslat fajl</a></p>');
?>
|
|
|
Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
|
|
Poslao: 24 Jul 2008 20:04
|
offline
- Web010
- Novi MyCity građanin
- Pridružio: 24 Jul 2008
- Poruke: 1
|
$query = "insert into automobili values
('".$marka."','".$model."','".$cena."','".$godiste."','".$boja."','".$email."','".$target_pa
th = "upload/"."')";
Jel ti ovo slucajna greska ili?
|
|
|
|
Poslao: 01 Avg 2008 12:48
|
offline
- Pridružio: 18 Dec 2007
- Poruke: 95
|
ih greska izvini nisam video!
Dopuna: 25 Jul 2008 12:51
('".$marka."','".$model."','".$cena."','".$godiste."','".$boja."','".$email."','".$slike."')"
;
Ovo je ispravljen.
ali ista stvar se dogadja.
Dopuna: 01 Avg 2008 12:48
sa ovom skriptom salje u bazu info o slici ime extenziju i to!ali nemogu da je iscitam!
ako ima neko skriptu za upis i citanje iz baze slika pa da vidim gde gresim!!!
<?php
$marka = $_POST['marka'];
$model = $_POST['model'];
$cena = $_POST['cena'];
$godiste = $_POST['godiste'];
$boja = $_POST['boja'];
$email = $_POST['email'];
$slike = $_FILES['slike'];
if (!$marka || !$model || !$cena || !$godiste || !$boja || !$email || !$slike)
{
echo 'Niste uneli tražene podatke.<br>'.
'Molimo vas pokušajte ponovo.';
exit;
}
if(!get_magic_quotes_gpc())
{
$marka = addslashes($marka);
$model = addslashes($model);
$cena = doubleval($cena);
$godiste = addslashes($godiste);
$boja = addslashes($boja);
$email = addslashes($email);
$slike = addslashes(fread(fopen($target_path = "upload/", "r")));;
}
@ $db = new mysqli('nemesis','ford','escort','automobili');
if (mysqli_connect_errno())
{
echo 'Greska neuspesno povezivanje sa bazom.'.
'Molimo pokusajte ponovo.';
exit;
}
$query = "insert into automobili values
('".$marka."','".$model."','".$cena."','".$godiste."','".$boja."','".$email."','".$_FILES['slike']['name']."')";
$result = $db->query($query);
if($result)
echo 'Podaci su uspesno unešeni.<br>';
$db->close();
print("$marka<br>");
print("$model<br>");
print("$cena<br>");
print("$godiste<br>");
print("$boja<br>");
print('<p><a href="mailto:'.$email.'">'.$email.'</a></p>');
?>
<?php
$uploaded=0;
$utime=time();
$uday= date('d');
$umonth= date('m');
$uyear= date('y');
$udate=$umonth.$uday.$uyear;
echo "Date:".$udate."<br>";
echo "Time:".$utime."<br>";
$filename="a".$udate.$utime;
echo "Create a unique name for a new file from date and time.<br>";
echo "Filename::".$filename."<br>";
$target_path = "/";
$target_path = $target_path . basename( $_FILES['slike']['name']);
echo "Target_path::".$target_path."<br><br>";
$_FILES['slike']['tmp_name']; // temp file
$target_path = "upload/"; //for my pc
echo "Read original name of the uploaded file <br>";
$original_file = basename($_FILES['slike']['name']);
echo "Original file::".$original_file."<br><br>";
echo "Getting the extention the file extension <br>";
$pos = strpos($original_file,".",0);
$ext = trim(substr($original_file,$pos+1,strlen($original_file))," ");
echo "extension::".$ext."<br>";
echo "Assemble new file name and extension <br>";
$slike = $filename . "." . $ext;
echo "New file name::".$slike."<br><br>";
echo "Move the file to the final destination <br>";
$target_path = $target_path . basename($slike);
echo "Target_path::".$target_path."<br><br>";
if(move_uploaded_file($_FILES['slike']['tmp_name'], $target_path)) {
$uploaded=1;
$message="Fajl je ". basename( $_FILES['slike']['name']). " uspesno poslat";
}
else
{
$message="Doslo je do greske prilikom slanja, molimo vas pokusajte ponovo!";
}
echo $message;
if($uploaded==1)
print('<p><a href="upload/'.$slike.'">Pogledaj poslat fajl</a></p>');
?>
|
|
|
|