slim

slim php framework image upload put database

♀尐吖头ヾ 提交于 2019-12-03 04:36:53
问题 I am new to slim php framework, I want to upload an image and put the file name in the database via POST , can some one kindly give me some example code. 回答1: Here's the router: $app->post('/', 'uploadFile'); this will point to the function below: function uploadFile () { if (!isset($_FILES['uploads'])) { echo "No files uploaded!!"; return; } $imgs = array(); $files = $_FILES['uploads']; $cnt = count($files['name']); for($i = 0 ; $i < $cnt ; $i++) { if ($files['error'][$i] === 0) { $name =

Slim - How to send response with “Content-Type: application/json” header?

混江龙づ霸主 提交于 2019-12-03 04:26:52
I have this simple REST api, done in Slim, <?php require '../vendor/autoload.php'; function getDB() { $dsn = 'sqlite:/home/branchito/personal-projects/slim3-REST/database.sqlite3'; $options = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ); try { $dbh = new PDO($dsn); foreach ($options as $k => $v) $dbh->setAttribute($k, $v); return $dbh; } catch (PDOException $e) { $error = $e->getMessage(); } } $app = new \Slim\App(); $app->get('/', function($request, $response) { $response->write('Bienvenidos a Slim 3 API'); return $response; }); $app->get('/getScore/{id:

Slim JSON Outputs

谁说胖子不能爱 提交于 2019-12-03 02:54:19
问题 I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than just exit($jsonEncodedVariable); . Am I missing something in the framework, or do I need to use json_encode() ... exit($json) ... for every method? All of the data is taken out of the my MySQL database and would then be put into a JSON array depending on what REST request was called. For example, if /api/posts/all was

Slim Framework for beginners [closed]

久未见 提交于 2019-12-03 01:43:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . How does anybody learn how to use this system? I can't seem to find any tutorials or books or anything on how to use this program. Yes their website briefly explains a few things but there is no clarification or anything. Google has failed me. Can anyone help me with this? I need to use this but it looks

Slim PHP and GET Parameters

人走茶凉 提交于 2019-12-03 01:28:30
问题 I'm playing with Slim PHP as a framework for a RESTful API, and so far it's great. Super easy to work with, but I do have one question I can't find the answer to. How do I grab GET params from the URL in Slim PHP? For example, if I wanted to use the following: http://api.example.com/dataset/schools?zip=99999&radius=5 A case of the Mondays? Am I overthinking it? Thanks in advance! 回答1: You can do this very easily within the Slim framework, you can use: $paramValue = $app->request()->params(

slim php framework image upload put database

旧街凉风 提交于 2019-12-02 17:46:22
I am new to slim php framework, I want to upload an image and put the file name in the database via POST , can some one kindly give me some example code. Muhaimin Here's the router: $app->post('/', 'uploadFile'); this will point to the function below: function uploadFile () { if (!isset($_FILES['uploads'])) { echo "No files uploaded!!"; return; } $imgs = array(); $files = $_FILES['uploads']; $cnt = count($files['name']); for($i = 0 ; $i < $cnt ; $i++) { if ($files['error'][$i] === 0) { $name = uniqid('img-'.date('Ymd').'-'); if (move_uploaded_file($files['tmp_name'][$i], 'uploads/' . $name) ==

Securing a REST API and Slim Framework

牧云@^-^@ 提交于 2019-12-02 17:45:00
I am fairly new to REST APIs, and I realize there are quite a few questions already posted. However, perusing these has actually left me more confused on how to handle this. I have created a REST API using Slim Framework which I am simply using to transfer data. I won't be using user logins or authentication, so I believe to secure this I just need a system that using a public key and a private key, but I am just not sure. If anyone has insight on the correct / most secure way to do this, or any tutorials / resources that would be great. Any help is appreciated. You can use SSL to encrypt data

Slim JSON Outputs

泄露秘密 提交于 2019-12-02 16:45:58
I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than just exit($jsonEncodedVariable); . Am I missing something in the framework, or do I need to use json_encode() ... exit($json) ... for every method? All of the data is taken out of the my MySQL database and would then be put into a JSON array depending on what REST request was called. For example, if /api/posts/all was requested, I would exit() a JSON array of all the posts which each value for its own key, "value" : key

Slim Framework for beginners [closed]

别说谁变了你拦得住时间么 提交于 2019-12-02 15:43:00
How does anybody learn how to use this system? I can't seem to find any tutorials or books or anything on how to use this program. Yes their website briefly explains a few things but there is no clarification or anything. Google has failed me. Can anyone help me with this? I need to use this but it looks completely foreign to me. UPDATE: After 3 years, It is time to add some updates to this answer. A lot has changed in slim framework (and even PHP) during this time. Slim version 3 has been released and brought some major changes to it. In my tests, It is slightly slower and tad more

Slim PHP and GET Parameters

孤街浪徒 提交于 2019-12-02 14:50:11
I'm playing with Slim PHP as a framework for a RESTful API, and so far it's great. Super easy to work with, but I do have one question I can't find the answer to. How do I grab GET params from the URL in Slim PHP? For example, if I wanted to use the following: http://api.example.com/dataset/schools?zip=99999&radius=5 A case of the Mondays? Am I overthinking it? Thanks in advance! Martijn You can do this very easily within the Slim framework, you can use: $paramValue = $app->request()->params('paramName'); $app here is a Slim instance. Or if you want to be more specific //GET parameter