上传PHP纤薄使用FTP
问题描述:
请参见下面的解决方案在后上传PHP纤薄使用FTP
我的PHP苗条网址正常工作在我的地方。 但如果我上传到使用FTP到我的在线服务器, 我得到404错误, 任何想法为什么?
这是我的路线代码:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$fb = new \Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.9',
]);
$app->options('/{routes:.+}', function ($request, $response, $args) {
return $response;
});
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST');
});
//get all
$app->post('/api/mykenteken', function (Request $request, Response $response) use ($fb){
$token = $request->getParam('token');
try {
$fb_response = $fb->get('/me', $token);
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo '{"error": {"text": "'.$e->getMessage().'"} }';
exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo '{"error": {"text": "'.$e->getMessage().'"} }';
exit;
}
$id = $request->getParam('id');
$sql = "SELECT * FROM test where id = $id";
try{
// Get DB Object
$db = new db();
// Connect
$db = $db->connect();
$stmt = $db->query($sql);
$users = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($users);
} catch(PDOException $e){
return $response->withStatus(400)->write('{"error": {"text": '.$e->getMessage().'}}');
}
});
我使用FileZilla中上传我的PHP苗条文件。 我在本地使用作曲家。
在我的本地我重定向我的IP,以localdev域
更新
我的PHP代码都在我的在线服务器上的这个路径:
域/的public_html /测试/ PHP
这是php文件夹的文件夹结构:
的.htaccess代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule^index.php [QSA,L]
Soltion
我得到了什么问题:
我必须寻找到这个文件夹:域/的public_html /测试/ php/public 而不是:domain/public_html
所以
的API必须的环节是:http://www.domain.nl/beta/php/public/myapilink 而不是:http://www.domain.nl/myapilink
答
404服务器错误,所以问题是,文件不可用,无法与你的代码什么。检查文件上传后是否设置为公开可读。即使文件被标记为这样,您也可能需要检查服务器上包含它的文件夹是否也设置为公共可读。
看着你的代码,两个问题突出。首先是$db = $db->connect();
需要一些指定数据库,用户名和密码的参数(或其他连接设置,具体取决于数据库的设置)。我不知道如何PHP引擎和数据库的设置,而是看你的代码,它很可能会涉及替换:
$db = new db();
的东西,如:
$db = new PDO("mysql:host=$servername;dbname=$dbName", $username, $password);
第二个问题是,您的代码非常容易受到SQL injection的影响。为了解决这个问题,替换:
$sql = "SELECT * FROM test where id = $id";
与
$sql = "SELECT * FROM test where id = :id";
和:
$stmt = $db->query($sql);
有:
$stmt = $db->prepare($sql);
$stmt->bindValue(':id', $id, PDO::PARAM_STR);
$stmt->execute();
这一过程被称为 “使用预处理语句”。它会为你节省很多心痛!
请显示您的代码。 –
嗨,本,我添加了一些代码 – Momen
听起来像是你错过了'.htaccess'文件或类似的东西。您的在线服务器是否使用Apache? – Phil