xref: /PHP-7.4/ext/curl/tests/bug48207.phpt (revision d6c05c6c)
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
37$ch = curl_init($url);
38$fp = fopen($tempfile, "r"); // Opening 'fubar' with the incorrect readonly flag
39curl_setopt($ch, CURLOPT_FILE, $fp);
40curl_exec($ch);
41curl_close($ch);
42is_file($tempfile) and @unlink($tempfile);
43isset($tempname) and is_file($tempname) and @unlink($tempname);
44?>
45--EXPECTF--
46Warning: curl_setopt(): the provided file handle is not writable in %s on line %d
47Hello World!
48Hello World!
49