Ergebnis 1 bis 5 von 5

Thema: [PHP] file put contents in PHP5

  1. #1

    [PHP] file put contents in PHP5

    Hi!

    Ich kämpfe zurzeit mit der file put contents function welche in PHP4 noch manuell eingegeben werden musste, in PHP 5 allerdings automatisch gehen sollte.

    Problem ist im endeffekt dass ich obwohl die function gelöscht worden ist, der code immer noch nicht geht. wäre also nett wenn jemand schnell nen blick drauf werfen würde und mir event. den fehler ausmerzen könnte

    Code:
    <?php
    // BolGalleryCreative - 05/03/2005
    // All right reserved to Nicolas d'Haussy
    // Use or modify it at your own risk
    
    // Coders : I commented this code as much as possible for you ;)
    // Coders : Need help at reducing file URLs expressions according to "current directory" PHP workflow style
    
    // Returns a GD image file resource create and its width and height into an array
    // Output array : {image resource, image width, image height}
    function getImageResource($imageFile) {
    
    	// Get image info
    	$imageFileInfo = getimagesize($imageFile);
    	$dataArray[1] = $imageFileInfo[0];
    	$dataArray[2] = $imageFileInfo[1];
    
    	// Create a image resource
     	if ($imageFileInfo[2] == 1) { $imageFileResource = imagecreatefromgif($imageFile); }
    	if ($imageFileInfo[2] == 2) { $imageFileResource = imagecreatefromjpeg($imageFile); }
     	if ($imageFileInfo[2] == 3) { $imageFileResource = imagecreatefrompng($imageFile); }
    	$dataArray[0] = $imageFileResource;
    	
    	return $dataArray;
    }
    
    
    
    // Creates a jpeg image sized as you want focusing randomly at a detail of the reference image
    function imageDetailExtract($referenceImage, $thumbnail, $thumbnailWidth, $thumbnailHeight, $thumbnailJpegQuality=70) {
    
    	$getImageResource = getImageResource($referenceImage);
    	
    	// Method to display a image detail
    	// Coders : problems with little images (To get rid of it, set those two variables to 0)
    	// Coders : could be also enhanced so as to see more details
    	$Xposition = round(rand(0, ($getImageResource[1]-$thumbnailWidth)));
    	$Yposition = round(rand(0, ($getImageResource[2]-$thumbnailHeight)));
    
    	// Create the detail image
    	$thumbnailResource = imagecreatetruecolor($thumbnailWidth,$thumbnailHeight);
    	imagecopy($thumbnailResource, $getImageResource[0], 0, 0, $Xposition, $Yposition, $getImageResource[1], $getImageResource[2]);
    	imagejpeg($thumbnailResource, $thumbnail, $thumbnailJpegQuality);
    	
    	// Destroy image resources
    	imagedestroy($getImageResource[0]);
    	imagedestroy($thumbnailResource);
    }
    
    
    
    // Resizes the given image outputting a jpeg image
    function resizeImage($referenceImage, $thumbnail, $maxWidth, $maxHeight, $thumbnailJpegQuality=70) {
    	
    	$getImageResource = getImageResource($referenceImage);
    	
    	// Recompute size for fitting (to be validated)
    	if( $getImageResource[1] > $getImageResource[2]) { $maxHeight = round(($getImageResource[2]/$getImageResource[1])*$maxWidth); }
    	else { $maxWidth = round(($getImageResource[1]/$getImageResource[2])*$maxHeight); }
    
    	// Create resized image
    	$thumbnailResource = imagecreatetruecolor($maxWidth,$maxHeight);
    	imagecopyresized($thumbnailResource, $getImageResource[0], 0, 0, 0, 0, $maxWidth, $maxHeight, $getImageResource[1], $getImageResource[2]);
    	imagejpeg($thumbnailResource, $thumbnail, $thumbnailJpegQuality);
    	
    	// Destroy image resources
    	imagedestroy($getImageResource[0]);
    	imagedestroy($thumbnailResource);
    }
    
    
    
    // Date sorting method
    function mtime_sort($b, $a) { 
    
    	if (filemtime($a) == filemtime($b)) {
    		return 0; 
    	} else {
    		return (filemtime($a) < filemtime($b)) ? -1 : 1; 
    	}
    } 
    
    
    
    
    // Creates bolGallery files and returns the HTML layout source string
    function bolGalleryCreate($imagesList, $referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic=false) {
    
    	// Build gallery HTML source
    	$HTML = "";
    
    // Bolgallery Javascript popup function
    $bolGalleryPopup = "<!-- BolGallery Javascript popup window function -->
    <SCRIPT type=\"text/javascript\">
    
    function bolGalleryPopup(imageFile, width, height, title){
    
    	var html = '<title>' + title + ' - Click to close </title><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onclick=\"javascript:window.close()\"><img src=\"' + imageFile + '\" alt=\"Click to close\"></body>';
    	var popup = window.open(imageFile, '_blank', 'width=' + width+ ', height=' + height + ', status=no');
    	popup.document.write(html);
    	popup.focus();
    }
    </SCRIPT>\n\n";
    $HTML .= $bolGalleryPopup;
    
    
    	// Build the HTML table to display all the thumbnails
    	$HTML .= "<!-- Generated by BolGallery - Nicolas d'Haussy - http://bolgallery.free.fr -->\n<TABLE border=0 cellspacing=0 cellpadding=0>\n\t<TR valign=\"top\">\n";
    	$table_i=0;
    
    	foreach($imagesList as $currentImage) {
    
    				// (Re)build thumbnail url string
    				$referenceImageName = str_replace($referenceImagesDirectory, "", $currentImage);
    				$thumbnail = ($referenceImagesDirectory . "bolGallery/thumbnail_" . $referenceImageName); 
    
    				// Get reference image file info
    				$referenceImageInfos = getimagesize($currentImage);
    				$referenceImageWidth = $referenceImageInfos[0];
    				$referenceImageHeight = $referenceImageInfos[1];
    
    				// Generate the thumbnail image if doesn't exist
    				if(! file_exists($thumbnail)) {
    				
    					// Generate mode style thumbnail
    					if($switchClassic) { resizeImage($currentImage, $thumbnail, $thumbnailWidth, $thumbnailHeight); } 
    					else { imageDetailExtract($currentImage, $thumbnail, $thumbnailWidth, $thumbnailHeight); }
    				}
    
    				// Display the thumbnail image and set a popup link to the big one
    				$alt = str_replace("_", " ", substr($referenceImageName, 0, -4)); 
    				$HTML .= "\t\t<TD align=\"center\">\n\t\t\t<A href=\"" . $currentImage . "\" onClick=\"bolGalleryPopup(this.href, " . $referenceImageWidth. ", " . $referenceImageHeight . ", '" . $alt . "'); return(false);\" target=\"_blank\">\n"; // target attribute to be tested
    				$HTML .= "\t\t\t\t<IMG src=\"" . $thumbnail . "\" title=\"" . $alt . "\" border=0>\n";
    				$HTML .= "\t\t\t</A>\n\t\t</TD>\n";
    				
    				// HTML table next line evaluation
    				$table_i++;
    				if (($table_i % $tableColumnsNb) == 0) {
    					$HTML .= "\t</TR>\n\t<TR valign=\"top\">\n";
    				}
    	}
    	$HTML .= "\t</TR>\n\t<TR>\n\t\t<TD colspan=" . $tableColumnsNb . ">\n\t\t\t<FONT size=1>Generated by <A href=\"http://bolgallery.free.fr\" target=\"_blank\">bolGallery</A></FONT>\n\t\t</TD>\n\t</TR>\n"; // Thanks not to delete this line
    	$HTML .= "</TABLE>\n<BR>\n<!--End BolGallery-->\n\n";
    	return $HTML;
    }
    
    
    // Main function. Handles bolGalleryCreate(). Call it on your php pages where you want it build a gallery.
    // Loads static page or lists reference images directory and launchs gallery creation
    function bolGallery($referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic=false) {
    
    		$staticPage = ("./" . str_replace(".", "", str_replace("/", "", $referenceImagesDirectory)) . "_bolGalleryStaticPage.html");
    		
    		// Recreate the gallery if there was any modification
    		if((!file_exists($staticPage)) or (filemtime($referenceImagesDirectory) > filemtime($staticPage))) {
    
    			// Builds an array (sorted by date) of image files from given directory
    			if (is_dir($referenceImagesDirectory)) { 
    
    				// Create the thumbnails directory if doesn't exist
    				if (! is_dir($referenceImagesDirectory."bolGallery")) {
    					mkdir($referenceImagesDirectory."bolGallery", 0755);
    				}
    
    				// Check the reference images directory (Doesn't scan subdirectories)
    				$handle=opendir($referenceImagesDirectory);
    				while ($file=readdir($handle)) {
    
    					if (is_file($referenceImagesDirectory.$file)) {
    
    						// Check if the file is an image
    						$extension = strtolower(substr(strrchr($file,  "." ), 1));
    						$supportedExtensions = array("jpg", "jpeg", "gif", "png");
    		
    						if (in_array($extension, $supportedExtensions) and ($file[0] != "#")) { // Also checks whether file is marked by a "#"
    		
    							// Add this file to the image files array
    							$imagesList[] = $referenceImagesDirectory.$file; // Should not add $referenceImagesDirectory in the array, could be added later
    						}
    					}
    				}
    				closedir($handle);
    
    				// Sort image files array by date with "mtime_sort" method
    				// Coders : could enable the user to choose between multiple file sorting
    				@usort($imagesList, "mtime_sort") or die("There are no image in <b>" . $referenceImagesDirectory . "</b> to run bolGallery.");
    
    			} else { die("<b>" . $referenceImagesDirectory . "</b> does not exist or is not a valid directory url. Cannot run bolGallery."); }
    
    			// Build gallery
    			$HTML = bolGalleryCreate($imagesList, $referenceImagesDirectory, $tableColumnsNb, $thumbnailWidth, $thumbnailHeight, $switchClassic);
    
    			// Bake also bolGallery HTML source output to file
    			$session = fopen($staticPage, "w"); // "r+" ?
    			fputs($session, "<!-- BolGallery baked HTML page -->\n".$HTML);
    			fclose($session);
    
    		}
    
    /* Won't work
    
    		// Load static page (the old one or the last created above)
    		require($staticPage) or die("<b>" . $staticPage . "</b> does not exist.");
    */
    
    		$pageString = file_get_contents($staticPage);
    		echo $pageString;
    }
    ?>
    Source: http://bolgallery.free.fr/

    Fehlermeldung ist diese hier:
    Code:
    Warning: fopen(./gallery_bolGalleryStaticPage.html) [function.fopen]: failed to open stream: Permission denied in /home/armitage/public_html/public/scripts/gallery/bolGallery.php on line 194
    
    Warning: fputs(): supplied argument is not a valid stream resource in /home/armitage/public_html/public/scripts/gallery/bolGallery.php on line 195
    
    Warning: fclose(): supplied argument is not a valid stream resource in /home/armitage/public_html/public/scripts/gallery/bolGallery.php on line 196
    
    Warning: file_get_contents(./gallery_bolGalleryStaticPage.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/armitage/public_html/public/scripts/gallery/bolGallery.php on line 206
    vielen dank!!
    A2k

  2. #2
    Permissions richtig setzen. Fehlermeldungen sind dazu da, das man sie *liest*.

  3. #3
    Kann mq nur zustimmen. Ordentliches FTP Programm besorgen und Berechtigungen für den Ordner, in dem die Webseite (oder das Skript) liegt auf 777 (alle lesen und schreiben und ausführen) setzen.
    Aber wie kommst du darauf, dass das irgendwas mit file_put_contents() zu tun hat? In deinem Code kommt die Funktion kein einziges Mal vor.

  4. #4
    Zitat Zitat von dead_orc Beitrag anzeigen
    777
    Versuchs noch mal. :P

  5. #5
    Zitat Zitat von Mog Beitrag anzeigen
    Versuchs noch mal. :P
    Ich weiß, das ist nicht sicher, und ich würds selber auch nie machen. Aber was hast du großartig für Möglichkeiten, wenn du einen Webspace hast, auf den du nur per FTP zugreifen kannst und vermutlich nichtmal weißt, als was für ein Benutzer der Webserver läuft. Besser wäre natürlich einen extra Ordner anzulegen, in dem Dateien, die der Webserver bearbeiten können soll, liegen, und diesen dann 1770 chmoddet und auf die Gruppe des Webservers setzt. Nur... das ist den meisten Leuten einfach egal.

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •