将 PHP 脚本转换为可执行文件
Transform PHP script into executable
我正在尝试创建一个脚本来将我的文件上传到 Google 云端硬盘。当我 运行 它时,它工作得很好。这是工作代码:
public function uploadToDrive()
{
$client = new Google_Client();
$client->setClientId(Mage::getStoreConfig('mtm_google/drive/client_id'));
$client->setClientSecret(Mage::getStoreConfig('mtm_google/drive/client_secret'));
$client->setRedirectUri(Mage::getStoreConfig('mtm_google/drive/redirect_uri'));
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else {
$client->setAccessToken($_SESSION['access_token']);
}
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$file->setName('analysis.csv');
$file->setDescription('A test document');
$data = file_get_contents('temp.csv');
$service->files->create($file, array(
'data' => $data,
'mimeType' => 'text/csv',
'uploadType' => 'multipart'
));
echo 'SUCCESS!';
unlink('temp.csv');
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
}
此脚本应该可以从控制台执行,而不是从某些 URL 执行。当我尝试从控制台执行此操作时,没有任何反应,因为会话变量和重定向是它无法处理的。我如何修改此脚本才能从控制台执行?
只是 define/set 个变量:$_GET, $_SESSION, ....
这些变量可以像控制台的参数一样使用 $argv[]
传递
我正在尝试创建一个脚本来将我的文件上传到 Google 云端硬盘。当我 运行 它时,它工作得很好。这是工作代码:
public function uploadToDrive()
{
$client = new Google_Client();
$client->setClientId(Mage::getStoreConfig('mtm_google/drive/client_id'));
$client->setClientSecret(Mage::getStoreConfig('mtm_google/drive/client_secret'));
$client->setRedirectUri(Mage::getStoreConfig('mtm_google/drive/redirect_uri'));
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else {
$client->setAccessToken($_SESSION['access_token']);
}
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$file->setName('analysis.csv');
$file->setDescription('A test document');
$data = file_get_contents('temp.csv');
$service->files->create($file, array(
'data' => $data,
'mimeType' => 'text/csv',
'uploadType' => 'multipart'
));
echo 'SUCCESS!';
unlink('temp.csv');
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
}
此脚本应该可以从控制台执行,而不是从某些 URL 执行。当我尝试从控制台执行此操作时,没有任何反应,因为会话变量和重定向是它无法处理的。我如何修改此脚本才能从控制台执行?
只是 define/set 个变量:$_GET, $_SESSION, ....
这些变量可以像控制台的参数一样使用 $argv[]