ted_chou12 Posted December 17, 2006 Share Posted December 17, 2006 this is a php script i found called 'gallery thingie', due to the fact that it has its own admin. login session, therefore, the intergration is twice harder. What the problem is, is that whenever i login on my on login session, the xml data gets "washed", for some reason, i cant seem to paste it on here, so is attached as a txt file, i believe is because the script is too long, but please dont lose interest to my problem.any part that you dont understand please reply to me, by the way, there are no session related things on the other document called publication.php, so i didn't post it on.forgive me if i am giving you a headache as wellthanks for any help or suggestions provided.TedEDITED: I cant get neither it pasted or attached as a txt file, why? Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/ Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 First quarter.[code]<?phpob_start();session_start();//my own sessionrequire_once ("functions.php");if (checkLoggedin()) echo "";else header("location: index.php"); // up until here, below gallery starts.require_once("publication.php"); // Link to the file with the public functions.?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><?phpfunction printValue($type) { global $_GET, $title, $name, $description; $id = $_GET["id"]; if ($_GET["action"] == "edit") { switch ($type) { case "title" : echo "value=\"{$title[$id]}\" "; break; case "description" : echo "value=\"{$description[$id]}\" "; break; case "id" : echo "value=\"{$_GET["id"]}\" "; break; } }}function printMenuItem($action, $text) { global $self; if (IsSet($_REQUEST["action"])) { if ($action == $_REQUEST["action"]) { if ($_REQUEST["action"] == "edit") { $id = "&id={$_GET["id"]}"; } echo "<a href=\"{$self}?action={$action}{$id}\" class=\"current\">{$text}</a>"; } else { if ($action == "") { if ($_REQUEST["action"] == "submitadd" || $_REQUEST["action"] == "submitedit" || $_REQUEST["action"] == "delete" || $_REQUEST["action"] == "submitcats") { echo "<a href=\"{$self}\" class=\"current\">{$text}</a>"; } else { echo "<a href=\"{$self}\">{$text}</a>"; } } else { echo "<a href=\"{$self}?action={$action}\">{$text}</a>"; } } } else { if ($action == "") { echo "<a href=\"{$self}\" class=\"current\">{$text}</a>"; } else { echo "<a href=\"{$self}?action={$action}\">{$text}</a>"; } }}function getExt ($name) { // This function returns the file ending without the "." if (strstr($name, ".")) { $ext = str_replace(".", "", strrchr($name, ".")); } else { $ext = ""; } return $ext;}function saveFile () { global $xmlfile, $name, $title, $description, $cat, $categories; $xmlstring = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<gallery>"; // Categories are added $xmlstring = "{$xmlstring}\r\n\t<categories>"; if (is_array($categories)) { foreach ($categories as $cid => $catname) { $xmlstring = "{$xmlstring}\r\n\t\t<category cid=\"{$cid}\">{$catname}</category>"; } } $xmlstring = "{$xmlstring}\r\n\t</categories>"; // Images are added $xmlstring = "{$xmlstring}\r\n\t<images>"; if (is_array($name)) { foreach ($name as $id => $filename) { $xmlstring = "{$xmlstring}\r\n\t\t<image id=\"{$id}\">\r\n\t\t\t<file>{$name[$id]}</file>\r\n\t\t\t<title>{$title[$id]}</title>\r\n\t\t\t<description>{$description[$id]}</description>\r\n\t\t\t<imgcategory>{$cat[$id]}</imgcategory>\r\n\t\t</image>"; } } $xmlstring = "{$xmlstring}\r\n\t</images>"; $xmlstring = "{$xmlstring}\r\n</gallery>"; if (is_writeable($xmlfile)) { $fp = fopen($xmlfile, "wb"); fputs ($fp, $xmlstring); fclose($fp); return TRUE; } else { return FALSE; }}?><?phpfunction updateCats($newcats) { global $categories; foreach ($newcats as $currentid => $currentcat) { $currentcat = strip_tags(stripslashes(trim($currentcat))); if ($currentcat != "") { $categories[$currentid] = $currentcat; } else { UnSet($categories[$currentid]); } } if (saveFile() == TRUE) { echo "<p class=\"ok\">Categories updated.</p>"; return TRUE; } else { echo "<p class=\"alarm\">Could not update data file.</p>"; return FALSE; }}[/code] Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/#findComment-143095 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 Second quarter[code]<?php//this not included.function editImage($oldid, $newid, $newtitle, $newdescription, $newcat, $filename = "", $updatethumb = "") { global $name, $title, $description, $cat, $enableThumbnails, $thumbnailwidth, $thumbnailquality, $path; $newdescription = stripslashes(trim($newdescription)); $newtitle = stripslashes(trim($newtitle)); if ($enableThumbnails == TRUE && $updatethumb != "") { // Delete old thumbnail file. if (!file_exists("{$path}thumbs/{$filename}") || !@unlink("{$path}thumbs/{$filename}")) { // Create thumbnail. $msg = createThumbnail($filename, $thumbnailwidth, $thumbnailquality); if ($msg == 0) { echo "<p class=\"ok\">Thumbnail updated.</p>"; } else { echo "<p class=\"alarm\">{$msg}</p>"; } } else { echo "<p class=\"alarm\">Old thumbnail file could not be deleted.</p>"; } } if ($oldid == $newid) { $title[$newid] = $newtitle; $description[$newid] = $newdescription; $cat[$newid] = $newcat; if (saveFile() == TRUE) { echo "<p class=\"ok\">Image edited.</p>"; return TRUE; } else { echo "<p class=\"alarm\">Could not update data file.</p>"; return FALSE; } } else { $newname = $name[$oldid]; if (!IsSet($name[$newid])) { if (deleteImage($oldid, "no", "no") == TRUE) { $name[] = $newname; $title[] = $newtitle; $description[] = $newdescription; $cat[] = $newcat; if (saveFile() == TRUE) { echo "<p class=\"ok\">Image edited.</p>"; return TRUE; } else { echo "<p class=\"alarm\">Could not update data file.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Could not remove old ID.</p>"; return FALSE; } } else { if (deleteImage($oldid, "no", "no") == TRUE) { $temp = array_splice($name, $newid); $name[] = $newname; foreach ($temp as $value) { $name[] = $value; } UnSet($temp); $temp = array_splice($title, $newid); $title[] = $newtitle; foreach ($temp as $value) { $title[] = $value; } UnSet($temp); $temp = array_splice($description, $newid); $description[] = $newdescription; foreach ($temp as $value) { $description[] = $value; } UnSet($temp); $temp = array_splice($cat, $newid); $cat[] = $newcat; foreach ($temp as $value) { $cat[] = $value; } UnSet($temp); if (saveFile() == TRUE) { echo "<p class=\"ok\">Image edited.</p>"; return TRUE; } else { echo "<p class=\"alarm\">Could not update data file.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Could not remove old ID.</p>"; return FALSE; } } }}[/code] Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/#findComment-143097 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 third quarter:[code]<?phpfunction deleteImage($id, $delfile = "yes", $output = "yes", $delthumb = "yes") { global $name, $description, $title, $cat, $path; if (IsSet($name[$id])) { if ($delfile == "yes") { if (@unlink("{$path}{$name[$id]}")) { echo "<p class=\"ok\">File deleted. "; } else { echo "<p class=\"alarm\">File not deleted. "; } } if ($delthumb == "yes") { if (@unlink("{$path}thumbs/{$name[$id]}")) { echo "<span class=\"ok\">Thumbnail deleted. </span>"; } else { echo "<span class=\"alarm\">Thumbnail not deleted. </span>"; } } $temp = array_splice($name, $id); array_shift($temp); foreach ($temp as $value) { $name[] = $value; } UnSet($temp); $temp = array_splice($title, $id); array_shift($temp); foreach ($temp as $value) { $title[] = $value; } UnSet($temp); $temp = array_splice($description, $id); array_shift($temp); foreach ($temp as $value) { $description[] = $value; } UnSet($temp); $temp = array_splice($cat, $id); array_shift($temp); foreach ($temp as $value) { $cat[] = $value; } UnSet($temp); if (saveFile() == TRUE) { if ($output != "no") { echo "<span class=\"ok\">Image removed.</span></p>"; } return TRUE; } else { if ($output != "no") { echo "<span class=\"alarm\">Could not update data file.</span></p>"; } return FALSE; } }}function createThumbnail($orgimg, $thumbnailwidth, $thumbnailquality) { global $path; $thumbpath = "{$path}thumbs/{$orgimg}"; $orgimg = "{$path}{$orgimg}"; $error = 0; if (function_exists('imagecreate') && function_exists('imagecopyresized')) { // Check if thumbnail directory exists. If not try to create it. if (!is_dir("{$path}thumbs")) { $oldumask = umask(0); if (@!mkdir("{$path}thumbs", 0777)) { $error = "Thumbnail directory could not be created."; } umask($oldumask); } // Get file size and file type. if ($error == 0) { if (!$size = @getimagesize($orgimg)) { $error = "Size of original image could not be calculated."; } } // Create link to old image. if ($error == 0) { switch ($size[2]) { case 1 : if (function_exists('imagecreatefromgif')) { $img = @imagecreatefromgif($orgimg); if ($img == "") { $error = "Could not open link to original image."; } } else { $error = "Could not open link to original image."; } break; case 2 : if (function_exists('imagecreatefromjpeg')) { $img = @imagecreatefromjpeg($orgimg); if ($img == "") { $error = "Could not open link to original image."; } } else { $error = "Could not open link to original image."; } break; case 3 : if (function_exists('imagecreatefrompng')) { $img = @imagecreatefrompng($orgimg); if ($img == "") { $error = "Could not open link to original image."; } } else { $error = "Could not open link to original image."; } break; default : $error = "Cannot create thumbnail. Original image is of an unsupported type."; break; } } // Calculate the dimensions of the new image. if ($error == 0) { if (!strstr($thumbnailwidth, "%")) { if($size[0] > $size[1]) { $ratio = $size[0]/$thumbnailwidth; $height = $size[1]/$ratio; $height = round($height); $width = $size[0]/$ratio; } else { $ratio = $size[1]/$thumbnailwidth; $width = $size[0]/$ratio; $width = round($width); $height = $size[1]/$ratio; } } else { $ratio = str_replace("%", "", $thumbnailwidth)/100; $width = round($size[0]*$ratio); $height = round($size[1]*$ratio); } }[/code] Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/#findComment-143099 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 4th plus some more[code]<?php // Create new image (true colour if available). if ($error == 0) { if (function_exists('imagecreatetruecolor')) { $newimg = imagecreatetruecolor($width, $height); } else { $newimg = imagecreate($width, $height); } } // Resample old image over new image. if ($error == 0) { if(!function_exists('imagecopyresampled') || !function_exists('imagecreatetruecolor')) { if (!@imagecopyresized($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) { $error = "Could not resize image."; } } else { if (!@imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) { $error = "Could not resample image."; } } } // Make the thumbnails, and save files. if ($error == 0) { switch ($size[2]) { case 1: if (!@imagegif($newimg, $thumbpath)) { $error = "Could not save thumbnail."; } break; case 2: if (!@imagejpeg($newimg, $thumbpath, $thumbnailquality)) { $error = "Could not save thumbnail."; } break; case 3: if (!@imagepng($newimg, $thumbpath)) { $error = "Could not save thumbnail."; } break; default : $error = "Could not create thumbnail. Image type not supported."; } } // Destroy image both links. @imagedestroy($newimg); @imagedestroy($img); } else { $error = "Image functions not available for thumbnail."; } return $error;}function addImage($newtitle, $newdescription, $newcat, $newfromfile) { global $name, $title, $description, $cat, $allowedfiles, $maxsize, $path, $enableThumbnails, $thumbnailwidth, $thumbnailquality; $newtitle = strip_tags(stripslashes(trim($newtitle))); $newdescription = strip_tags(stripslashes(trim($newdescription))); $newfromfile = strip_tags(stripslashes(trim($newfromfile))); // If there are no categories configured we add a category if ($newcat == "NoCatIsAvailable") { $temp = array("Untitled"); updateCats($temp); UnSet($temp); $newcat = 0; } // Check if there is a file uploaded. If there is use that if not check if there is something in the "enter file name" field. if ($newtitle != "") { if ($_FILES["localfile"]["error"] == 0 || ($newfromfile != "" && file_exists("{$path}{$newfromfile}"))) { if (IsSet($_FILES["localfile"]["tmp_name"])) { // A file has been uploaded. if (in_array(strtolower(getExt($_FILES["localfile"]["name"])), $allowedfiles)) { if (in_array(strtolower(getExt($_FILES["localfile"]["name"])), $allowedfiles)) { if (filesize($_FILES["localfile"]["tmp_name"]) <= $maxsize) { if (@move_uploaded_file($_FILES["localfile"]["tmp_name"], "{$path}{$_FILES["localfile"]["name"]}")) { // Build and save the xml data file. $name[] = $_FILES["localfile"]["name"]; $title[] = $newtitle; $description[] = $newdescription; $cat[] = $newcat; if (saveFile() == TRUE) { if ($_POST["submit"] != "Add Image") { UnSet($_REQUEST["action"]); } else { $_REQUEST["action"] = "add"; } echo "<p class=\"ok\">Image added.</p>"; if ($enableThumbnails == TRUE) { $msg = createThumbnail($_FILES["localfile"]["name"], $thumbnailwidth, $thumbnailquality); if ($msg == 0) { echo "<p class=\"ok\">Thumbnail created.</p>"; } else { echo "<p class=\"alarm\">{$msg}</p>"; } } return TRUE; } else { echo "<p class=\"alarm\">Error: The script couldn't save the data file.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: The script couldn't move the file.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: The file was too big.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: This type of image is not allowed.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: This type of image is not allowed.</p>"; return FALSE; } } else { // Check if the file name given exists or return error. if (in_array(strtolower(getExt($newfromfile)), $allowedfiles)) { if (file_exists("{$path}{$newfromfile}")) { // Build and save the xml data file. $name[] = $newfromfile; $title[] = $newtitle; $description[] = $newdescription; $cat[] = $newcat; if (saveFile() == TRUE) { if ($_POST["submit"] != "Add Image") { UnSet($_REQUEST["action"]); } else { $_REQUEST["action"] = "add"; } echo "<p class=\"ok\">Image added.</p>"; if ($enableThumbnails == TRUE) { $msg = createThumbnail($newfromfile, $thumbnailwidth, $thumbnailquality); if ($msg == 0) { echo "<p class=\"ok\">Thumbnail created.</p>"; } else { echo "<p class=\"alarm\">{$msg}</p>"; } } return TRUE; } else { echo "<p class=\"alarm\">Error: The script couldn't save the data file.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: The file you tried to link this entry could not be found.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: This type of image is not allowed.</p>"; return FALSE; } } } else { echo "<p class=\"alarm\">Error: You did not specify a file for upload (or the file was too big) or the file you tried to link do not exist.</p>"; return FALSE; } } else { echo "<p class=\"alarm\">Error: You did not specify a title.</p>"; return FALSE; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/#findComment-143100 Share on other sites More sharing options...
ted_chou12 Posted December 17, 2006 Author Share Posted December 17, 2006 5th[code] <div> <label for="newtitle">Title: </label> <input type="text" name="newtitle" id="newtitle" size="30" <?php printValue("title");?>/> </div> <div> <label for="newdescription">Description: </label> <input name="newdescription" id="newdescription" size="30" <?php printValue("description");?>/> </div> <div> <label for="newcat">Category: </label> <select name="newcat" id="newcat"><?phpif (is_array($categories)) { foreach ($categories as $key => $currentcat) { if ($_GET["action"] == "edit" && $cat[$_GET["id"]] == $key) { echo "\t\t\t\t\t\t<option value=\"{$key}\" selected=\"selected\">{$currentcat}</option>\r\n"; } else { echo "\t\t\t\t\t\t<option value=\"{$key}\">{$currentcat}</option>\r\n"; } }} else { echo "\t\t\t\t\t\t<option value=\"NoCatIsAvailable\">No category is available</option>\r\n";}?> </select> </div><?php if ($_GET["action"] == "edit") { ?> <div> <input type="checkbox" class="checkbox" name="thumb" id="thumb" /> <label class="checkbox" for="thumb">Update thumbnail.</label> </div> <div> <input type="hidden" name="filename" value="<?php echo $name[$_GET["id"]];?>" /> <input type="hidden" name="action" value="submitedit" /> <input type="hidden" name="oldid" value="<?php echo $_GET["id"];?>" /> <input type="submit" value="Edit image" /><?php } else { ?> <div> <label for="localfile">File: </label> <input type="file" name="localfile" id="localfile" /> </div> <div> <label for="newfilename">Or link to file: </label> <input type="text" name="newfilename" id="newfilename" /> </div> <div> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxsize;?>" /> <input type="hidden" name="action" value="submitadd" /> <input type="submit" name="submit" value="Add Image" class="half" /> <input type="submit" name="submit" value="Add & Exit" class="half" /><?php } ?> </div> </fieldset> </form><?php } elseif ($_REQUEST["action"] == "cats") { ?> <form action="<?php echo $self;?>" method="post"> <table> <thead> <tr> <th class="center">#</th> <th>Category</th> </tr> </thead> <tbody><?php$categories[] = "";foreach ($categories as $currentid => $currentcat) { if ($currentid%2 == 0) { echo "\t\t\t\t<tr class=\"org\">"; } else { echo "\t\t\t\t<tr class=\"alt\">"; } echo "\r\n\t\t\t\t<td class=\"center\">{$currentid}</td>\r\n\t\t\t\t<td><input type=\"text\" name=\"newcats[]\" value=\"{$currentcat}\" /></td>\r\n\t\t\t</tr>\r\n";}?> </tbody> <tfoot> <tr><td colspan="2"><input type="hidden" name="action" value="submitcats" /><input type="submit" value="Submit changes" /></td></tr> </tfoot> </table> </form><?php } else {?> <table> <thead> <tr bordercolor="#111111"> <th class="center">#</th> <th>Title</th> <th>Category</th> <th>Description</th> <th>File name</th> <th>Dimensions</th> <th class="center">Size</th> <th class="center">Options</th> </tr> </thead> <tbody><?phpif (is_array($name)) { $totalsize = 0; foreach ($name as $currentid => $currentfile) { if (file_exists("{$path}{$currentfile}")) { $currentsize = @filesize("{$path}{$currentfile}")/1024; $totalsize = $totalsize+$currentsize; $currentsize = round($currentsize, 1); $currentdimensions = @getimagesize("{$path}{$currentfile}"); if ($enableThumbnails == TRUE && !file_exists("{$path}thumbs/{$currentfile}")) { $thumbExists = " †"; } else { $thumbExists = ""; } if ($currentid%2 == 0) { echo "\t\t\t\t<tr class=\"org\">"; } else { echo "\t\t\t\t<tr class=\"alt\">"; } if (strlen($description[$currentid]) > $limit) { $currentdescription = trim(substr($description[$currentid], 0, $limit))."..."; } else { $currentdescription = $description[$currentid]; } echo "\r\n\t\t\t\t\t<td class=\"center\">{$currentid}</td>\r\n\t\t\t\t\t<td><a href=\"{$phpfile}?id={$currentid}\">{$title[$currentid]}</a>{$thumbExists}</td>\r\n\t\t\t\t\t<td><a href=\"{$phpfile}?category={$cat[$currentid]}\">{$categories[$cat[$currentid]]}</a></td>\r\n\t\t\t\t\t<td>{$currentdescription}</td>\r\n\t\t\t\t\t<td><a href=\"{$path}{$currentfile}\">{$currentfile}</a></td>\r\n\t\t\t\t\t<td class=\"center\">{$currentdimensions[0]}x{$currentdimensions[1]}</td>\r\n\t\t\t\t\t<td class=\"center\">{$currentsize}kb</td>\r\n\t\t\t\t\t<td><a href=\"{$self}?action=edit&id={$currentid}\">edit</a> / <a href=\"{$self}?action=delete&id={$currentid}\" onclick=\"if(checkDelete() == true) {return true;} else {return false;}\">del</a></td>\r\n\t\t\t\t</tr>\r\n"; UnSet($currentsize); UnSet($currentdimensions); UnSet($currentdescription); } else { echo "\t\t\t\t<tr>\r\n\t\t\t\t\t<td colspan=\"7\" class=\"alarm\">File not found: {$currentfile}</td>\r\n\t\t\t\t\t<td><a href=\"{$self}?action=edit&id={$currentid}\">edit</a> / <a href=\"{$self}?action=delete&id={$currentid}\" onclick=\"if(checkDelete() == true) {return true;} else {return false;}\">del</a></td>\r\n\t\t\t\t</tr>\r\n"; } }} else { echo "\t\t\t\t<tr>\r\n\t\t\t\t\t<td colspan=\"8\" class=\"alarm\">No images in database.</td>\r\n\t\t\t\t</tr>\r\n";}$totalsize = round($totalsize, 2);?> </tbody> <tfoot> <tr> <td colspan="8"><?php echo count($name);?> image(s) taking up <?php echo $totalsize;?>kb</td> </tr> </tfoot> </table><?php}}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/31013-problem-with-intergrating-a-photo-gallery-script-session-cause-file-write-over/#findComment-143101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.