Ciao a tutti ragazzi sto creando uno script di upload con la possibiltà di creare la propria immagine con diversi filtri... questo è il codice, solo che appena lo carico mi restituisce questo errore:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
Codice PHP:
<?php
//Collegamento MySql
$db = mysql_connect('localhost', 'root', '********') or
die ('Non è possibile connttersi');
mysql_select_db('moviesite', $db) or die (mysql_error ($db));
//cartella images
$dir= 'C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/images';
//gestisce l'immagine caricata
if ($_POST ['submit'] == 'Upload') {
//Si assicura che il caricamento si avvenuto
if ($_FILES ['uploadfile'] ['error'] != UPLOAD_ERR_OK) {
switch ($_FILES ['uploadfile'] ['error'] ) {
case UPLOAD_ERR_INI_SIZE:
die('File troppo grande' . 'in php.ini.');
break;
case UPLOAD_ERR_FORM_SIZE:
die ('The Upload file troppo grande' . 'specificato nell html');
break;
case UPLOAD_ERR_PARTIAL:
die ('the upload files was only partially upload');
break;
case UPLOAD_ERR_NO_FILE:
die ('No file was upload');
break;
case UPLOAD_ERR_TMP_DIR:
die ('The server is missing a temporary folder');
break;
case UPLOAD_ERR_CANT_WRITE:
die ('The server failed to write upload');
break;
case UPLOAD_ERR_EXTENSION:
die ('The upload stopped extension');
break;
}
}
//Recupera le info delle immagini appena caricata
$image_caption = $_POST ['caption'];
$image_username = $_POST ['username'];
$image_date = date ('Y-m-d');
list ($width, $height, $type, $attr) =
getimagesize ($_FILES ['uploadfile'] ['tmp_name']);
//Controlla se il il file caricato è supportato
$error = 'The file you upload non è supportato ';
switch ($type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif ($_FILES ['uploadfile'] ['tmp_name']) or die
($error);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg ($_FILES ['uploadfile'] ['tmp_name']) or die
($error);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng ($_FILES ['uploadfile'] ['tmp_name']) or die
($error);
break;
default:
die ($error);
}
//Inserisce nella tabella Image le info
$query = 'INSERT INTO images
(image_caption, image_username, image_date)
VALUES
("' . $image_caption . '", "' . $image_username . '", "' . $image_date . '")';
$result = mysql_query($query, $db) or die (mysql_error ($db));
//Recupera il valore di image_id da mysql
$last_id = mysql_insert_id ();
$image_id = $last_id;
imagejpeg ($image, $dir . '/' . $image_id . '.jpg');
imagedestroy ($image);
} else {
//recupera le info
$query = 'SELECT
image_id, image_caption, image_username, image_date
FROM
images
WHERE
image_id = '. $_POST ['id'];
$result = mysql_query($query, $db) or die (mysql_error ( $db));
extract (mysql_fetch_assoc ($result));
list ($width, $height, $type, $attr) = getimagesize ($dir . '/' . $image_id . '.jpg');
}
if ($_POST ['submit'] == 'Save') {
// si assicura che l'immagine sia valida
if (isset ($_POST ['id']) && ctype_digit ($_POST ['id']) &&
file_exists ($dir . '/' . $_POST ['id'] . '.jpg')) {
$image = imagecretefromjpeg ($dir . '/' . $_POST ['id'] . '.jpg');
} else {
die ('invalid image specified');
}
//applica filtro
$effect = (isset ($_POST ['effect'])) ? $_POST ['effect'] : -1;
switch ($effect) {
case IMG_FILTER_NEGATE:
imagefilter ($image, IMG_FILTER_NEGATE);
break;
case IMG_FILTER_GRAYSCALE:
imagefilter ($image, IMG_FILTER_GRAYSCALE);
break;
case IMG_FILTER_EMBOSS:
imagefilter ($image, IMG_FILTER_EMBOSS);
break;
case IMG_FILTER_GAUSSIAN_BLUR:
imagefilter ($image, IMG_FILTER_GAUSSIAN_BLUR);
break;
}
//salva l'immagibe cob filtro
imagejpeg ($image, $dir . '/' . $_POST ['id'] . '.jpg', 100);
?>
<html>
<head>
<title>Immagine</title>
</head>
<body>
<h1> La tua immagine è salvata ! </h1>
[img]images/<?php echo $_POST ['id']; ?>.jpg[/img]
</body>
</html>
<?php
} else {
?>
<html>
<head>
<title> La tua immgine </title>
</head>
<body>
<h1> So how does it fell famous? </h1>
<?php
if ($_POST ['submit'] == 'Upload') {
$imagename = 'images/' . $image_id . '.jpg' ;
}
else {
$imagename = 'image_effect.php?id=' . $image_id . '&e=' .
$_POST['effect'];
}
?>
[img]<?php echo $imagename; ?>[/img]
<table>
<tr>
<td> Immagina salvata come: </td><td><?php echo $image_id . '.jpg'; ?></td>
</tr>
<tr><td>Altezza: </td><td> <?php echo $height; ?> </td></tr>
<tr><td>Lunghezza: </td><td> <?php echo $width; ?> </td></tr>
<tr><td>Caricata il: </td><td> <?php echo $image_date; ?> </td></tr>
</table>
You may apply a special effect to yoput iamge from the list of option
Note: saving an image wih filtres [i]cannot be undone [/i]</p>
<form action="<?php echo $_SERVER ['PHP_SELF']; ?>" method="post">
<div>
<input type="hidden" name="id" value="<?php echo $image_id; ?>" />
<select name="effect">
<option value="-1">None </option>
<?php
echo '<option value="' . IMG_FILTER_GRAYSCALE . '"';
if (isset ($_POST ['effect'] ) && $_POST['effect'] == IMG_FILTER_GRAYSCALE) {
echo ' selected="selected"';
}
echo '> Black and White </option>';
echo '<option value="' . IMG_FILTER_GAUSSIAN_BUR . '"';
if (isset ($_POST ['effect'] ) && $_POST['effect'] == IMG_FILTER_GAUSSIAN_BUR) {
echo ' selected="selected"';
}
echo '> Blur </option>';
echo '<option value="' . IMG_FILTER_EMBOSS . '"';
if (isset ($_POST ['effect'] ) && $_POST['effect'] == IMG_FILTER_EMBOSS) {
echo ' selected="selected"';
}
echo '> Emboss </option>';
echo '<option value="' . IMG_FILTER_NEGATE . '"';
if (isset ($_POST ['effect'] ) && $_POST['effect'] == IMG_FILTER_NEGATE) {
echo ' selected="selected"';
}
echo '> Negative </option>';
?>
</select>
<input type="submit" value="anteprima" name="submit" />
<input type="submit" value="Save" name="submit" />
</div>
</form>
</body>
</html>
<?php
}
?>