xref: /PHP-5.4/ext/curl/tests/bug48207.phpt (revision 11f667e8)
1--TEST--
2Test curl_setopt() CURLOPT_FILE readonly file handle
3--CREDITS--
4Mark van der Velden
5#testfest Utrecht 2009
6--SKIPIF--
7<?php if (!extension_loaded("curl")) print "skip"; ?>
8--FILE--
9<?php
10/*
11 * Description       : Adds a file which stores the received data from curl_exec();
12 * Source code       : ext/curl/multi.c
13 * Test documentation: http://wiki.php.net/qa/temp/ext/curl
14 */
15
16// Figure out what handler to use
17$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
18if(!empty($host)) {
19
20    // Use the set Environment variable
21    $url = "$host/get.php?test=1";
22
23} else {
24
25    // Create a temporary file for the test
26    $tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
27    $url = 'file://'. $tempname;
28
29    // add the test data to the file
30    file_put_contents($tempname, "Hello World!\nHello World!");
31}
32
33
34$tempfile	= tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
35
36$ch = curl_init($url);
37$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
38curl_setopt($ch, CURLOPT_FILE, $fp);
39curl_exec($ch);
40curl_close($ch);
41is_file($tempfile) and @unlink($tempfile);
42isset($tempname) and is_file($tempname) and @unlink($tempname);
43?>
44--EXPECTF--
45Warning: curl_setopt(): the provided file handle is not writable in %s on line %d
46Hello World!
47Hello World!
48