Hi!
I have a content management system on my website. Recently all my pages which involve image uploads have stopped working properly and give the error:
[B]Warning[/B]: copy(/68.jpg) [[function.copy](http://www.hayleyneil.co.uk/cms/function.copy)]: failed to open stream: Permission denied in [B]/home/thesite/public_html/cms/galleryEditCategories.php[/B] on line [B]79[/B]
<?php include '../includes/config.inc.php'; ?>
<!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>Hayley CMS :: Edit/Delete Gallery Categories</title>
<link type="text/css" rel="stylesheet" href="css/styles.css" media="all" />
<script language="javascript" type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
</head>
<body>
<h1>Edit/Delete Gallery Categories</h1>
<?php
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$getCategories = @mysql_query("SELECT id, title, short_desc, long_desc FROM gallery_categories WHERE id=$id LIMIT 1");
if (!$getCategories) {
exit ("<p>Error retrieving requested information:" . mysql_error() . "</p>\
\
");
}
$categories = @mysql_fetch_array($getCategories);
$title = $categories['title'];
$longDesc = $categories['short_desc'];
$shortDesc = $categories['long_desc'];
?>
<h3>Alter information as necessary. You may change the category picture by uploading a new photo.</h3>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
<label for="title">Title</label><input name="title" type="text" value="<?php echo $title;?>" />
<label for="image">Image</label><input name="image" type="file" />
<label for="shortdesc">Short Description</label><textarea name="shortdesc" rows="5" cols="40"><?php echo $shortDesc;?></textarea>
<label for="longdesc">Long Description</label><textarea name="longdesc" rows="10" cols="40"><?php echo $longDesc;?></textarea>
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input name="update" type="submit" value="Update Category" class="submit" />
</form>
<?php
} else {
if (isset($_POST['updateorder'])) {
$orderArray = $_POST['order'];
$idArray = $_POST['id'];
$number_of_cats = count($idArray);
$counter = 0;
while( $counter < $number_of_cats ) {
mysql_query( "UPDATE gallery_categories SET disp_order=$orderArray[$counter] WHERE id=$idArray[$counter]" );
echo "<p>Order $counter updated!</p>";
$counter++;
}
} else {
if (isset($_POST['update'])) {
$id = $_POST['id'];
$title = $_POST['title'];
$shortDesc = $_POST['shortdesc'];
$longDesc = $_POST['longdesc'];
$image = $_FILES['image'];
$updateCats = mysql_query( "UPDATE gallery_categories SET title='$title', short_desc='$shortDesc', long_desc='$longDesc' WHERE id='$id' LIMIT 1" );
if (!$updateCats) {
exit ("<h3>Category editing not saved!</h3>\
".
"<p>Please <a href='javascript:history.go(-1)'>try again</a> or <a href='mailto:$webmasterCMS Error Editing Gallery Categories'>notify the webmaster\
\
</p>");
} else {
echo "<h3>Category successfully changed!</h3>\
";
}
if ($image['size'] > 0) {
if ($image['type'] == ('image/jpeg'||'image/pjpeg')) {
$filename = $id.".jpg";
if (!copy($image['tmp_name'], $uploadDir."/".$filename)) {
echo "<p>Image was not uploaded. Please try again.</p>";
} else {
list($width, $height, $type, $attr) = getimagesize($uploadDir."/".$filename);
if($width > $height) { //if landscape
$thumbnail_height = 100;
$thumbnail_width = (int)(100 * $width / $height);
} else { //if portrait
$thumbnail_height = (int)(100 * $height / $width);
$thumbnail_width = 100;
}
exec("convert $uploadDir/$filename -geometry {$thumbnail_width}x{$thumbnail_height} -gravity center -crop 100x100+0+0 $uploadDir/tb_$filename");
unlink($uploadDir."/".$filename);
echo "<p>Image uploaded successfully!</p>";
}
} else {
echo "<p>Image is not a JPEG.</p>";
}
} else {
echo "<p>Image not changed.</p>";
}
} else {
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$deleteSql1 = mysql_query("DELETE FROM gallery_categories WHERE id='$id' LIMIT 1");
if (!$deleteSql1) {
exit ("<h3>Category not deleted!</h3>\
".
"<p>Please <a href='javascript:history.go(-1)'>try again</a> or <a href='mailto:$webmasterCMS Error Deleting Gallery Category'>notify the webmaster\
\
</p>");
} else {
echo "<h3>Gallery Category Successfully Deleted!</h3>\
";
}
$deleteSql2 = mysql_query("DELETE FROM gallery_photos WHERE catid='$id'");
if (!$deleteSql2) {
exit ("<h3>Category photo entries not deleted!</h3>\
".
"<p>Please <a href='javascript:history.go(-1)'>try again</a> or <a href='mailto:$webmasterCMS Error Deleting Gallery Category Photos'>notify the webmaster\
\
</p>");
} else {
echo "<h3>Category photo entries Successfully Deleted!</h3>\
";
}
unlink("../images/photos/categories/tb_$id.jpg");
$dirname = "../images/photos/".$id;
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
}
// Clean up
$dir->close();
return rmdir($dirname);
}
rmdirr($dirname);
} else {
$categoryList = @mysql_query("SELECT `id`, `title`, `short_desc`, `disp_order` FROM `gallery_categories` ORDER BY `disp_order` ASC");
if (!$categoryList) {
exit ("<p>Error retrieving requested information:" . mysql_error() . "</p>\
\
");
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<table class="cmstable" cellpadding="5" cellspacing="5" border="0"><thead><td>Image</td><td class="title">Title & Short Description</td><td align="center">Edit</td><td align="center">Delete</td><td align="center">Display Order</td></thead>
<?php
// Create array function
while ($category = mysql_fetch_array($categoryList)) {
$id = $category['id'];
$title = $category['title'];
$shortDesc = $category['short_desc'];
$order = $category['disp_order'];
echo "<tr valign='top'><td><img src='../images/photos/categories/tb_$id.jpg' alt='$title' title='$title' width='100' height='100' /></td>".
"<td><h5>$title</h5><p>$shortDesc</p></td>".
"<td align='center'><a href='galleryEditCategories.php?edit=$id'><img src='images/icon_edit.gif' alt='Edit' title='Edit' border='0' /></a></td>".
"<td align='center'><a href='galleryEditCategories.php?delete=$id' onclick=\\"return confirm('Are you sure you want to delete this category and all photos within it?')\\"><img src='images/icon_delete.gif' alt='Delete' title='Delete' border='0' /></a></td>".
"<td align='center'><input type='text' value='$order' name='order[]' size='1' class='coods' style='text-align:center;' /><input type='hidden' name='id[]' value='$id' /></td></tr>";
}
?>
</table>
<input class="submit" type="submit" name="updateorder" value="Update Order" />
</form>
<?php
}
}
}
}
?>
</body>
</html>
I’ve changed my server since and it’s almost as if the copy function isn’t working properly now. Could anyone please help me!
Cheers!