ImageSet: $IMGSET_Name

"; // test for the existence of the upload directories, and if they're not there, create them. if (!file_exists("uploads/ImageSets/")) { mkdir("uploads/ImageSets/"); chmod("uploads/ImageSets/", 0777); } if (!file_exists("uploads/ImageSets/$IMGSET_Name")) { mkdir("uploads/ImageSets/$IMGSET_Name"); chmod("uploads/ImageSets/$IMGSET_Name", 0777); } // create a quick gallery of thumbs (without the editing options). $imagelist = ReadImageDir($IMGSET_Name); foreach($imagelist as $imagename) { if (substr($imagename, 0, 6) == "thumb_") { $output .= ""; $output .= ""; $output .= "\n"; } } $output .= "
"; $output .= "Edit ImageSet
"; return $output; } function EditImageSet($pagename) { global $IsPagePosted,$EditFields,$EditFunctions,$FmtV,$Now, $HandleEditFmt,$PageStartFmt,$PageEditFmt,$PagePreviewFmt,$PageEndFmt; global $pagename, $directory, $UploadDir; // grab the environment variables passed in the url $IMGSET_Name = $_GET["setname"]; // Test for correct authentication (uses permissions for the edit action). $page = RetrieveAuthPage($pagename,'edit'); if (!$page) Abort("?cannot edit $pagename"); $output .= DrawThumbs($IMGSET_Name); // put the page into the HandleEditFmt variable. SDV($HandleEditFmt, array(&$PageStartFmt, $output, &$PageEndFmt)); PrintFmt($pagename,$HandleEditFmt); //print "Username: ". $_SERVER['PHP_AUTH_USER'] ."
Pass: $PHP_AUTH_PW"; } // an image has been uploaded, so save it to the relevant directory and add a thumbnail function HandlePostImageSet() { global $IsPagePosted,$EditFields,$EditFunctions,$FmtV,$Now, $HandleEditFmt,$PageStartFmt,$PageEditFmt,$PagePreviewFmt,$PageEndFmt; global $uploadfile, $uploadfile_name, $crossloadfile, $pagename, $UploadDir; // copy the POSTed file into the uploads directory $IMGSET_Name = $_GET["setname"]; $IMGSET_CrossloadFile = $_POST["crossloadfile"]; // recieve an uploaded file if(!empty($uploadfile)) { if(copy($uploadfile, "$UploadDir/ImageSets/$IMGSET_Name/".$uploadfile_name)) { $output = "Successfully uploaded $uploadfile_name."; CreateThumb($uploadfile_name); } else { $output = "error uploading $uploadfile_name!"; } } // download a file from an URL if(!empty($IMGSET_CrossloadFile)) { $IMGSET_NewImageName = ""; //try to generate a filename for the image $ext = substr($IMGSET_CrossloadFile, -3); if(strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png") { // file has an image extension, so try use the filename out of the url. $crossload_filename = explode("/", $IMGSET_CrossloadFile); $IMGSET_NewImageName = $crossload_filename[count($crossload_filename) - 1]; } else { // image might not have a filename, so generate a random one. list($width, $height, $type, $attr) = getimagesize($IMGSET_CrossloadFile); if($type == 1) $IMGSET_NewImageName = rand().".gif"; if($type == 2) $IMGSET_NewImageName = rand().".jpg"; if($type == 3) $IMGSET_NewImageName = rand().".png"; } $fp = @fopen("$UploadDir/ImageSets/$IMGSET_Name/$IMGSET_NewImageName","w"); fwrite($fp,file_get_contents($IMGSET_CrossloadFile) ); fclose($fp); CreateThumb("$IMGSET_NewImageName"); $output .= "Crossloaded $IMGSET_CrossloadFile to $UploadDir/ImageSets/$IMGSET_Name/$IMGSET_NewImageName"; // get the file extension /* $ext = substr($IMGSET_CrossloadFile, -3); if($ext == "jpg" || $ext == "gif" || $ext == "png") { //file_put_contents(file_get_contents()); $crossload_filename = explode("/" } else { $output .= "The crossload URL does not appear to be an image file, trying anyway..."; }*/ //file_put_contents("$UploadDir/ImageSets/$IMGSET_Name/test.jpg", file_get_contents($IMGSET_CrossloadFile)); //file_get_contents(); } $output .= DrawThumbs($IMGSET_Name); // put the page into the HandleEditFmt variable. SDV($HandleEditFmt, array(&$PageStartFmt, $output, &$PageEndFmt)); PrintFmt($pagename,$HandleEditFmt); } function HandleDeleteImage() { global $IsPagePosted,$EditFields,$EditFunctions,$FmtV,$Now, $HandleEditFmt,$PageStartFmt,$PageEditFmt,$PagePreviewFmt,$PageEndFmt; global $pagename, $UploadDir; $IMGSET_Name = $_GET["setname"]; $IMGSET_ImageFile = $_GET["imgname"]; // try to delete the file and its thumbnail if(unlink("$UploadDir/ImageSets/$IMGSET_Name/$IMGSET_ImageFile")) { $output = "Successfully deleted $UploadDir/ImageSets/$IMGSET_Name/$IMGSET_ImageFile.
"; if(unlink("$UploadDir/ImageSets/$IMGSET_Name/thumb_$IMGSET_ImageFile")) { $output = "Successfully deleted $UploadDir/ImageSets/$IMGSET_Name/thumb_$IMGSET_ImageFile.
"; } } else { $output = "error deleting $UploadDir/ImageSets/$IMGSET_Name/$IMGSET_ImageFile!"; } $output .= DrawThumbs($IMGSET_Name); SDV($HandleEditFmt, array(&$PageStartFmt, $output, &$PageEndFmt)); PrintFmt($pagename,$HandleEditFmt); } //UTILITY FUNCTIONS:------------------------------------------------------------------------------------ function ReadImageDir($IMGSET_Name) { $output = array(); // traverse directory $dir = @opendir("uploads/ImageSets/$IMGSET_Name"); //if (!$dir) $output = "This ImageSet is empty"; while (($file=readdir($dir)) !== false) { if ($file{0} == '.') continue; // grab the last 3 characters of the filename (ie. the extension) $ext = substr($file, -3, 3); if(strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png") array_push($output, $file); } closedir($dir); return $output; } // Draw the gallery of thumbnails. function DrawThumbs($IMGSET_Name) { global $UploadDir, $pagename; $output = "

Editing ImageSet: $IMGSET_Name

[Return to $pagename] [Delete This ImageSet]
"; $imagelist = ReadImageDir($IMGSET_Name); foreach($imagelist as $imagename) { if (substr($imagename, 0, 6) == "thumb_") { $output .= ""; $output .= ""; $output .= "". substr($imagename, 6) ."
".round((filesize("$UploadDir/ImageSets/$IMGSET_Name/".substr($imagename,6))/1024),0)."KB"; $output .= "
[Change] [Delete]

"; } } $output .= "
Upload a new file:

Crossload a file from an URL:
"; return $output; } // Create a thumbnail from an image, with max dimensions 100x100. function CreateThumb($image) { global $UploadDir; $IMGSET_Name = $_GET["setname"]; $imagepath = "$UploadDir/ImageSets/$IMGSET_Name/$image"; // full path to the image $info = getimagesize($imagepath); $width = $info[0]; $height = $info[1]; $type = $info[2]; if ($type == 1) $new = imagecreatefromgif($imagepath); elseif ($type == 2) $new = imagecreatefromjpeg($imagepath); elseif ($type == 3) $new = imagecreatefrompng($imagepath); if ($height > $width) { $newheight = 100; $newwidth = $width/($height/$newheight); } else { $newwidth = 100; $newheight = $height/($width/$newwidth); } $newimage = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newimage, $new, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if ($type == 1) imagegif($newimage, "$UploadDir/ImageSets/$IMGSET_Name/thumb_$image"); elseif ($type == 2) imagejpeg($newimage, "$UploadDir/ImageSets/$IMGSET_Name/thumb_$image"); elseif ($type == 3) imagepng($newimage, "$UploadDir/ImageSets/$IMGSET_Name/thumb_$image"); } ?>