-
-
Notifications
You must be signed in to change notification settings - Fork 1
WebRequest
StefansArya edited this page Apr 18, 2019
·
3 revisions
You may need to import this feature on top of your code.
use \Scarlets\Library\WebRequest;
Web Request with curl extension
WebRequest::loadURL($url, $options = null)
url
can also be an array if you would like to do parallel request in a time.
$data = WebRequest::loadURL('https://www.google.com', [
'ssl'=>false, // Skip ssl verification
'header'=>['some'=>'header'],
'data'=>['key' => 'value'],
# If you have deep key value data you
# should use `JSON_POST` for the method
'method'=>'POST',
'cookiefile'=>'path/to/file',
'cookie'=>'urlencoded=data',
'limitSize'=>10, // In KB
'proxy'=>['ip' => '127.0.0.1', 'port' => 8000],
'returnheader' => true // Return header only
]);
Send file from this server to client browser
WebRequest::giveFiles($filePath, $fileName = null)
Download file from other server to local file.
Multiple file download also supported.
WebRequest::download($assocArray, $options = null)
// Example:
WebRequest::download([$fromURL => $toPath], [
/* This $options is similar like loadURL */
]);
Get Content-Size
of an URL
WebRequest::contentSize($url);
Receive uploaded file from client browser to this server
WebRequest::receiveFile($field, $dirPath, $allowedExt, $fileName = null);
// Example
<input name="myFile" type="file">
WebRequest::receiveFile('myFile', '/home/storage', ['css', 'js', 'png']);
Make sure you limit the allowed extension to
avoid security issue.