...

View Full Version : Error when uploading image in database



daniedb
08-03-2006, 05:42 PM
Hi,

I get the following error when uploading an image to the database:

Warning: unlink() failed (Permission denied) in c:\phpdev\www\clartal\admin\images.php on line 82

The thumb photo is uploaded successfully but the bigphoto doesn't want to display.

I've installed PHPDev3 from firepages.

Here's the coding:

<?php
if ($_SESSION['adminuserid'] and $_SESSION['adminusername']) {

if (($Submitimage) and ($_FILES['imagefile']['tmp_name'])) {
$doimage = true;
if ($_FILES['imagefile']['type'] != 'image/pjpeg') { // ($_FILES['imagefile']['type'] != 'image/gif') - GIF not supported at this time
echo "Nie n geldige foto formaat nie. Slegs en .jpg formaat toegelaat. Huidige formaat: ".$_FILES['imagefile']['type']."<br>";
unlink($_FILES['imagefile']['tmp_name']);
$doimage = false;
} else {
list($imgwidth, $imgheight, $a, $b) = getimagesize($_FILES['imagefile']['tmp_name']);
if (($imgwidth > 500) or ($imgheight > 500)) {
echo "Foto se dimensies te groot. Foto is ".$imgwidth."x".$imgheight."pixels en moet kleiner wees as 500x500pixels.<br>";
unlink($_FILES['imagefile']['tmp_name']);
$doimage = false;
}
}
if ($_FILES['imagefile']['size'] > 32000) {
echo "Foto is te groot (ler grote). Foto is ".$_FILES['imagefile']['size']."bytes groot en mag slegs 30000 bytes wees.<br>";
unlink($_FILES['imagefile']['tmp_name']);
$doimage = false;
}
} elseif (($Submitimage) and !($_FILES['imagefile']['tmp_name'])) {
echo "Foto nie opgelaai nie.<br>Moonlikke rede: Foto ler te groot. Foto moet kleiner as 30000 bytes wees.<br>of: geen foto gespesifiseer.<br>";
$doimage = false;
}

if ($doimage) {
$f1 = fopen($_FILES['imagefile']['tmp_name'], "r");
$f2 = fread($f1, $_FILES['imagefile']['size']);
$f2 = addslashes($f2);
$fname = strtolower(basename($_FILES['imagefile']['name']));
$ftype = $_FILES['imagefile']['type'];

$picshape = '';

if ($imgwidth >= $imgheight) {
if ($imgwidth/$imgheight < 2) {
$sizechange = 100/$imgwidth;
$picshape = 'square';
} else {
$sizechange = 200/$imgwidth;
$picshape = 'wide';
}
} elseif ($imgwidth < $imgheight) {
if ($imgheight/$imgwidth < 2) {
$sizechange = 100/$imgheight;
$picshape = 'square';
} else {
$sizechange = 200/$imgheight;
$picshape = 'tall';
}
}
$newwidth = round($imgwidth * $sizechange);
$newheight = round($imgheight * $sizechange);

if ($ftype == 'image/pjpeg') {
$destimg = imagecreatetruecolor($newwidth,$newheight);
$srcimg = imagecreatefromjpeg($_FILES['imagefile']['tmp_name']);
imagecopyresized($destimg, $srcimg, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
ob_start();
imagejpeg($destimg);
$t1 = addslashes(ob_get_contents());
ob_end_clean();
}
/* elseif ($ftype == 'image/gif') {
* $destimg = imagecreatetruecolor($newwidth,$newheight);
* $srcimg = imagecreatefromgif($_FILES['imagefile']['tmp_name']);
* imagecopyresized($destimg, $srcimg, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
* ob_start();
* imagegif($destimg);
* $t1 = addslashes(ob_get_contents());
* ob_end_clean();
* }
*/

if ($txtcomment == "") { $txtcomment = "&nbsp;"; }
$imgsql = "INSERT INTO images VALUES ('', '1','$fname', '$txtcomment', '$lstcategory', '$ftype', '$picshape', '$f2', '$t1')";
$doimage = mysql_query($imgsql, $db) or die("<font color=\"red\">Foto nie opgelaai!!!</font> Foto naam bestaan reeds of ander fout.");
echo "Foto ".$_FILES['imagefile']['name']." opgelaai.<br>";
//unset($_FILES['imagefile']['tmp_name']);
unlink($_FILES['imagefile']['tmp_name']);
}
if ($action == 'delete') {
$sql = "DELETE FROM images WHERE iindex='$indx'";
echo "<p>Rekord verwyder</p>";
$action = "";
$result = mysql_query($sql, $db);
}

?>
<p><a href="#editbottom">Voeg nuwe foto by</a></p>
<table border="1" cellspacing="0" cellpadding="3" bordercolor="#CCCCCC">
<tr>
<!-- <th>&nbsp;</th> -->
<th>Thumb Foto</th>
<th>Beskrywing</th>
<th>Kategorie</th>
<th>&nbsp;</th>
</tr>
<?php
$imgquery = mysql_query("SELECT iindex, comment, category, image_type FROM images ORDER BY category, iindex", $db);
while ($imgresult = mysql_fetch_row($imgquery)) {
// header("Content-type: $imgresult[3]");
printf("<tr> <!-- <td><a href=\"index.php?id=images&action=edit&indx=%s#editbottom\">verander</a><br>(Slegs kategorie en beskrywing)</td> --> <td><img src=\"showthumb.php?tid=%s\"></td><td>&nbsp;%s</td><td>%s</td><td><a href=\"index.php?id=images&action=delete&indx=%s\">wis uit</a></td></tr>", $imgresult[0], $imgresult[0], $imgresult[1], $imgresult[2], $imgresult[0]);
}

?>
</table>
<a name="editbottom"></a>
<form name="frmImages" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="action" value="<?=$action?>">
<input type="hidden" name="indx" value="<?=$tindx?>">

<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="2">
<ul>
<li>Slegs JPG foto's</li>
<li>Kleiner as 30K</li>
<li>Kleiner as 500x500 pixels</li>
</ul>
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="MAX_FILE_SIZE" value="32000">
<input type="file" name="imagefile" size="50">
</td>
</tr>
<tr>
<td>Kategorie:</td>
<td>
<select name="lstcategory">
<option value="gallery">gallery</option>
<?php
$catquery = mysql_query("SELECT category FROM imagecategories WHERE category != 'gallery' ORDER BY category", $db);
while ($catresult = mysql_fetch_row($catquery)) {
printf("<option value=\"%s\">%s</option>", $catresult[0], $catresult[0]);
}
?>
</select>
</td>
</tr>
<tr>
<td>Foto onderskrif:</td>
<td>
<input type="text" name="txtcomment" size="50" maxlength="255">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submitimage" value="Stuur">
</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?php
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum