We recently made a server change FreeBSD-->Linux, and I'm debugging some of my php. One error I found happens when I try to upload an image to a directory. My steps were:
1. fopen, x mode (Create & open with write access, if file does exist return false).
2. Curl an image, and output it to my file.
3. Close the file.
This worked great on my previous server. Now it returns this error:
Code: Select all
Fatal error: curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: fopencookie failed in /var/www/bbm/dealsontheweb.com/beta_htdocs/sandbox/curl.php on line 29Some perhaps relevant configuration info:
Code: Select all
Previous Server:
PHP Version: 5.2.1
--with-curl
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
cURL: libcurl/7.13.1 OpenSSL/0.9.8a zlib/1.1.4
New Server:
PHP Version: 5.2.6RC4-pl0-gentoo
--with-curl --without-curlwrappers
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
cURL: libcurl/7.17.1 OpenSSL/0.9.8g zlib/1.2.3Code: Select all
<?php
$sub_dir = "/sandbox/upload/";
$basename = "logo";
$ext = ".gif";
$image_url = "http://www.google.com/intl/en_ALL/images/logo.gif";
$upload = $_SERVER['DOCUMENT_ROOT'].$sub_dir.$basename.$ext;
$handle = @fopen(urldecode($upload), "x");
if (!$handle) {
$copy="";
$n = 1;
$upload = $_SERVER['DOCUMENT_ROOT'].$sub_dir.$basename.$copy.$ext;
while(file_exists(urldecode($upload))) {
$copy = "_copy" . $n;
++$n;
$upload=$_SERVER['DOCUMENT_ROOT'].$sub_dir.$basename.$copy.$ext;
$filename = $basename.$copy.$ext;
}
$handle = fopen(urldecode($upload), "x");
}
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $image_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $handle);
$image = curl_exec($ch);
curl_close($ch);
fclose($handle);
?>