xref: /PHP-8.0/ext/curl/tests/bug48207.phpt (revision 517c9938)
1--TEST--
2Test curl_setopt() CURLOPT_FILE readonly file handle
3--CREDITS--
4Mark van der Velden
5#testfest Utrecht 2009
6--SKIPIF--
7<?php include 'skipif.inc'; ?>
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
17include 'server.inc';
18$host = curl_cli_server_start();
19if(!empty($host)) {
20
21    // Use the set Environment variable
22    $url = "$host/get.inc?test=1";
23
24} else {
25
26    // Create a temporary file for the test
27    $tempname = tempnam(sys_get_temp_dir(), 'CURL_HANDLE');
28    $url = 'file://'. $tempname;
29
30    // add the test data to the file
31    file_put_contents($tempname, "Hello World!\nHello World!");
32}
33
34
35$tempfile	= tempnam(sys_get_temp_dir(), 'CURL_FILE_HANDLE');
36$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
37
38$ch = curl_init($url);
39try {
40    curl_setopt($ch, CURLOPT_FILE, $fp);
41} catch (ValueError $exception) {
42    echo $exception->getMessage() . "\n";
43}
44
45curl_exec($ch);
46curl_close($ch);
47is_file($tempfile) and @unlink($tempfile);
48isset($tempname) and is_file($tempname) and @unlink($tempname);
49?>
50--EXPECT--
51curl_setopt(): The provided file handle must be writable
52Hello World!
53Hello World!
54