From ff8c56927c4922605f74bb59f6bfc7e95276279a Mon Sep 17 00:00:00 2001
From: aoneil <aoneil@467b73ca-7a2a-4603-9d3b-597d59a354a9>
Date: Mon, 17 Sep 2007 01:19:15 +0000
Subject: [PATCH] Don't show open_basedir errors when curl can't access temp
 dir

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/phpinstaller/trunk@42178 467b73ca-7a2a-4603-9d3b-597d59a354a9
---
 install.php     | 25 ++++++++++++++-----------
 rewritetest.php | 21 ++++++++++++---------
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/install.php b/install.php
index d6629a7..c40cebb 100644
--- a/install.php
+++ b/install.php
@@ -681,7 +681,7 @@ PHP
 	function createFile($filename, $content) {
 		$base = $this->getBaseDir();
 
-		if(($fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
+		if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
 			return true;
 		} else {
 			$this->error("Couldn't write to file $base$filename");
@@ -816,16 +816,19 @@ TEXT
 		// Workaround for 'URL file-access is disabled in the server configuration' using curl
 		if(function_exists('curl_init')) {
 			$ch = curl_init($location);
-			$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
-			curl_setopt($ch, CURLOPT_FILE, $fp);
-			curl_setopt($ch, CURLOPT_HEADER, 0);
-			curl_exec($ch);
-			curl_close($ch);
-			fclose($fp);
-			$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
-			unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
-			if($testrewriting == 'OK') {
-				return true;
+			$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
+			
+			if($fp) {
+				curl_setopt($ch, CURLOPT_FILE, $fp);
+				curl_setopt($ch, CURLOPT_HEADER, 0);
+				curl_exec($ch);
+				curl_close($ch);
+				fclose($fp);
+				$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+				unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+				if($testrewriting == 'OK') {
+					return true;
+				}
 			}
 		}
 		
diff --git a/rewritetest.php b/rewritetest.php
index 6e9dc95..fc8730d 100644
--- a/rewritetest.php
+++ b/rewritetest.php
@@ -54,15 +54,18 @@ function performModRewriteTest() {
 	if(function_exists('curl_init')) {
 		$ch = curl_init($location);
 		$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
-		curl_setopt($ch, CURLOPT_FILE, $fp);
-		curl_setopt($ch, CURLOPT_HEADER, 0);
-		curl_exec($ch);
-		curl_close($ch);
-		fclose($fp);
-		$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
-		unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
-		if($testrewriting == 'OK') {
-			return true;
+		
+		if($fp) {
+			curl_setopt($ch, CURLOPT_FILE, $fp);
+			curl_setopt($ch, CURLOPT_HEADER, 0);
+			curl_exec($ch);
+			curl_close($ch);
+			fclose($fp);
+			$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+			unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
+			if($testrewriting == 'OK') {
+				return true;
+			}
 		}
 	}