Skip to content

Commit 1e51025

Browse files
author
Josh Pettett
committed
use file handles instead of '@' notation to upload files
1 parent d721980 commit 1e51025

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

examples/sendFiles.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
$params = array(
77
'to' => $toNumber,
88
'file' => array(
9-
# Create files and put their names here prefixed with '@'
10-
'@files/coverPage.html',
11-
'@files/content.pdf'
9+
# Use open file handles to upload files
10+
fopen('files/coverPage.html', 'r'),
11+
fopen('files/content.pdf', 'r')
1212
)
1313
);
1414

lib/Phaxio.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,13 @@ private function curlSetoptCustomPostfields($ch, $postfields, $headers = null)
186186
}
187187
foreach ($fields as $field) {
188188
list($key, $value) = $field;
189-
if (strpos($value, '@') === 0) {
190-
preg_match('/^@(.*?)$/', $value, $matches);
191-
list($dummy, $filename) = $matches;
189+
if (is_resource($value)) {
190+
$filename = stream_get_meta_data($value)['uri'];
192191
$body[] = '--' . $boundary;
193192
$body[] = 'Content-Disposition: form-data; name="' . $key . '"; filename="' . basename($filename) . '"';
194193
$body[] = 'Content-Type: application/octet-stream';
195194
$body[] = '';
196-
$body[] = file_get_contents($filename);
195+
$body[] = stream_get_contents($value);
197196
} else {
198197
$body[] = '--' . $boundary;
199198
$body[] = 'Content-Disposition: form-data; name="' . $key . '"';

0 commit comments

Comments
 (0)