出于某种原因,我的脚本今天停止了工作 当我查看API控制面板时,我仍然有100%的使用率.有任何想法吗?他们改变了auth方式吗?
function url_small($url)
{
//This is the URL you want to shorten
$longUrl = $url;
$apiKey = '#####HIDDEN######';
//Get API key from : http://code.google.com/apis/console/
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
//change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
return $json->id;
}
Run Code Online (Sandbox Code Playgroud)
响应
stdClass Object …Run Code Online (Sandbox Code Playgroud) Linux SSH
我用php创建一个文件
if (!is_dir(DIR_FILE))
mkdir(DIR_FILE, 0777);
$filename = DIR_FILE . $id . '.txt';
$handle_cf = fopen($filename, 'a');
fwrite($handle_cf, $data . "\n");
fclose($handle_cf);
chmod($filename, 0777);
chown($filename, "usr111"); // usr111 = username
chgrp($filename, "usr111"); // usr111 = group that is also attached to apache
Run Code Online (Sandbox Code Playgroud)
该文件获得以下权限.
-rwxrwxrwx 1 apache apache 1447 Apr 4 12:48 D.txt
-rwxrwxrwx 1 apache apache 1447 Apr 4 12:48 E.txt
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试删除该文件时,在常规用户帐户(usr111)下.我收到以下错误
[usr111@host session]$ rm D.txt
rm: cannot remove `D.txt': Permission denied
Run Code Online (Sandbox Code Playgroud)
注意:我可以删除root下的文件.
找到FIX!即使我在mkdir上使用模式设置为php.出于某种原因,这不起作用.我添加了以下内容.
if (!is_dir($dir)) {
mkdir($dir, 0777); …Run Code Online (Sandbox Code Playgroud)