Witam,
Więc tak mam taki skrypt. I chce by nazwa z upladowanego pliku była władowana do mysql'a
<?
$host = "localhost";
$user = "root";
$pass = "";
$name = "felis_foto";
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dokument bez tytułu</title>
</head>
<body>
<?php
if ($_POST['dodaj']) {
$id=$_GET['id'];
$newname1 = trim($_POST['newname']); // próbowałem też z nazwa 'image_name' i tak nie pobiera
//define a maxim size for the uploaded images in Kb
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
if (!$i) { return ""; }
return $ext;
}
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
//get the extension of the file in a lower case format
$extension = getExtension($filename);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>'; $errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>'; $errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder)
$newname="tmp/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>'; $errors=1;
}}}
//If no errors registred, print the success message
// sprawdza czy taka podstrona jest w bazie
$zapytanie = "SELECT nazwa FROM foto WHERE id='$id'";
else {
$zapytanie = "INSERT INTO foto (id, foto) VALUES ('$id', '$newname1')";
if ($wstaw){
$zapytanie="SELECT * FROM `foto` WHERE `id` LIKE '$id'";
{
$nazwa = $wiersz['nazwa'];
$id = $wiersz['id'];
}
echo "<div id='dymkaP'>Fotografia została właśnie dodana. Posiada identyfikator o numerze ".$id.". </div>"; }
else
echo "<div id='dymkaN'>Dodanie Fotografi do bazy nie powiodło się.</div>"; }
}
?>
<div id="okno">
<form enctype="multipart/form-data" action="index.php" method="POST" name="newad">
<div class="oknoDane">
<p class="oknoDanePotrzebne">Podaj Potrzebne Dane:</p>
<table><tr>
<td><table><tr>
<td>fotografia:</td><td><input type="file" name="image" class="nazwy" /></td></tr></table></td>
</tr></table>
</div>
<div class="pagesPrzyciski">
<input type="submit" name="dodaj" class="pages" value="Dodaj" />
<input type="reset" class="pages" value="Resetuj" />
<input type="button" class="pages" onclick="java script:history.back();" name="wstecz" value="Wstecz" />
</div>
</form>
</div>
</body>
</html>