So far i have tried below:
...
public function upload()
{
$jwplatform_api = new Jwplayer\JwplatformAPI('my_key', 'my_secret');
$target_file = 'upload/vids/course/bede6b9c266b876fc2f0dea7a86cf8bd.mp4';
$params = array();
$params['title'] = 'PHP API Test Upload';
$params['description'] = 'Video description here';
// Create video metadata
$create_response = json_encode($jwplatform_api->call('/videos/create', $params));
$decoded = json_decode(trim($create_response), TRUE);
$upload_link = $decoded['link'];
$upload_response = $jwplatform_api->upload($upload_link, $target_file);
print_r($upload_response);
}
...
But no luck, it says "Class 'Jwplayer\JwplatformAPI' not found".
And yeah, i have put the files I got from https://github.com/jwplayer/jwplatform-php in the ROOT position inside a folder named "jwplatform-php".
Ok since you don't want to use composer - here is a guide
1. Download as Zip
2. Create a folder
In your folder application/third_party/ create a folder called jwplatformapi/
3. Unpack the init.php and the src folder
Unpack from your zip file the init.php and the src folder into your application/third_party/jwplatformapi/ folder
it should looke like
4. Create your library
Create a file called Jwplatform_library.php in your application/libraries/ folder
class Jwplatform_library
{
private $key;
private $secret;
public function __construct($key = 'my_key', $secret = 'my_secret')
{
$this->key = $key;
$this->secret = $secret;
}
public function get()
{
require_once(APPPATH.'third_party/jwplatformapi/init.php');
return new Jwplayer\JwplatformAPI($this->key, $this->secret);
}
}
5. use it in one of your controllers
public function upload()
{
$this->load->library('Jwplatform_library', ['my_key', 'my_secret']);
$obj = $this->jwplatform_library->get();
var_dump($obj);
}
Related
Hi need help in creating nested folders.
I currently have a folder called images and i would like to clone the folders and save it in a different folder call backup. and the backup will only happen when user clicks backup.
For example:
- Images
- Car
- A
- A1
- A1-1
- A2
- B
- Van
How can i write the code so that it will create the folders?
Currently i have done this so how can i do it?
public function sync(Request $request)
{
$arr = [];
$folderToSync = $request->input('folderName');
$originalPath = public_path($folderToSync);
$newFolderPath = public_path('S3/'.$folderToSync);
$this->createFolder($newFolderPath); // create the selected folder
$directories = $this->getAllFolders($originalPath); // getting all folders under the original path
$this->folder($directories, $newFolderPath, $originalPath);
dd('end');
}
public function createFolder($path)
{
if (!is_dir($path)) {
#mkdir($path, 0777, true);
}
}
public function folder($directories, $newFolderPath, $originalPath)
{
foreach ($directories as $directory) {
$newPath = $newFolderPath.'/'.$directory;
$oriPath = $originalPath.'/'.$directory;
$this->createFolder($newPath);
$subFolders = $this->getAllFolders($oriPath);
if ($subFolders) {
$this->subfolder($subFolders, $newPath);
}
}
}
public function subfolder($directories, $path)
{
foreach ($directories as $directory) {
$this->createFolder($path.'/'.$directory);
}
}
public function getAllFolders($path)
{
return array_map('basename', \File::directories($path));
}
public function getAllFiles($path)
{
return;
}
but its not creating the subfolders. How can i modify it ?
i would run the code every week and i want to check also which folder have been created and which have not been created. if the folder does not exist then create the folder.
I would have a look at the storage api from the Laravel documentation: https://laravel.com/docs/5.7/filesystem#directories
To acquire folders and subfolders:
// Recursive...
$directories = Storage::allDirectories($directory);
Creating a new directory:
Storage::makeDirectory($directory);
Storing files:
Storage::put('file.jpg', $contents);
Storage::put('file.jpg', $resource);
The put method will take either the file contents or a resource.
Don't forget to include the Storage facade:
use Illuminate\Support\Facades\Storage;
I am studying some laravel code that I downloaded and I am getting some problem.
This supposed to be the functions to save,delete and download the files but the problem is.
The files are being saved in a folder named with a number on "storage\app\public\project-files\" (i.e. storage\app\public\project-files\11), both destroy and download methods are referencing different paths, I tried to change but didn't worked, download show FileNotFoundException and destroy just remove from the database but not from the folder
So is this code wrong? How It supposed to be?
I've read about using artisan:link but seems odd to me run this command every time I want upload a file to make a link
PS. I cheched the routes, so the methods are being called
Thanks
public function store(Request $request)
{
if ($request->hasFile('file')) {
$file = new ProjectFile();
$file->user_id = $this->user->id;
$file->project_id = $request->project_id;
$request->file->store('public/project-files/'.$request->project_id);
$file->filename = $request->file->getClientOriginalName();
$file->hashname = $request->file->hashName();
$file->size = $request->file->getSize();
$file->save();
$this->project = Project::find($request->project_id);
return view('project-files');
}
public function destroy($id)
{
$file = ProjectFile::find($id);
File::delete('storage/project-files/'.$file->project_id.'/'.$file->hashname);
ProjectFile::destroy($id);
$this->project = Project::find($file->project_id);
return view('project-files');
}
public function download($id) {
$file = ProjectFile::find($id);
return response()->download('storage/project-files/'.$file->project_id.'/'.$file->hashname);
}
You are storing files in storage so i assume you have uploaded image in the following path
project\storage\app\public\project-files
if this is the path then you can delete using
Storage::delete('public/project-files/1.JPG');
for Downlaoding file
$path= storage_path('app/public/project-files/3.JPG');
return response()->download($path);
I want to write a class and save it into application/models/ folder.
The code is as below:-
function writeANewFile()
{
$path = "/LMSV1/application/models/";
$classname = "firstidgenerator";
$this->load->helper('file');
$data = "<?php class ".$classname." extends CI_Model {
function generateId(\$db)
{
\$data['orders'] = 'orders';
\$this->\$db->trans_start();
\$this->\$db->insert('$classname', \$data);
\$insert_id = \$this->\$db->insert_id();
\$this->\$db->trans_complete();
return \$insert_id;
}
} ";
$result = write_file(''.$path.''.$classname.'.php', $data);
echo json_encode($result);
} //end fucntion
If i give the $path = "c:/xampp/htdocs/FrameWorks/LMSV1/application/models/"; then it successfully saves a file in desired folder.
But if if i give $path = "/LMSV1/application/models/"; then it returns false and does not create a file.
The problem lies in setting path and i could not successfully figure out what should be the path to be given as parameter?
Codeigniter has a few path constants that are useful in this case. The constant APPPATH is what you need.
$path = APPPATH . "models/";
I want to use TesseractOCR in zend framework 2 project, i've installed TesseractOCR and when i call recognize function from an action i get the following errors:
file_get_contents(/tmp/1999512125.txt): failed to open stream: No such file or directory in var/www/res-admin/vendor/thiagoalessio/tesseract_ocr/TesseractOCR/TesseractOCR.php on line 235
unlink(/tmp/1999512125.txt): No such file or directory in /var/www/res-admin/vendor/thiagoalessio/tesseract_ocr/TesseractOCR/TesseractOCR.php on line 248
I need to read email address from a hosted image like this one.
This is the function from where i call TesseractOCR recognize function:
public function getTextFromImage($img){
$tesseract = new TesseractOCR($img);
return $tesseract->recognize();
}
and this is the action:
public function emailAction(){
$request = $this->getRequest();
if ($request->isPost())
{
$id = $request->getPost('id');
$maj = $this->email($id);
$data = new JsonModel(array(
'success' => true,
'maj' => $maj
));
return $data;
}
}
where email is:
public function email($source){
$maj = 0;
if($source=='toutes les sources') $annonces = $this->getAnnonces();
else $annonces = $this->getAnnoncesBySource($source);
foreach($annonces as $annonce){
$annonce['email'] = $this->getTextFromImage($annonce['email_annonceur']);
$this->updateEmail($annonce);
$maj +=1;
}
return $maj;
}
Does not seems to be a zf2 related pb.
Look at your tmp file *.txt if it exists and if rights are well set.
If it does not exist check why in the source method.
If it exists, check your rights.
No more ;).
I have a class which is meant to "load" an another class, however I haven't been able to get it to work.
Error Message
Fatal error: Call to undefined method stdClass::echoString() in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\classes\example.php on line 5
Code
My code is broken up into three main sections:
api.php - the class to load the other classes.
API/exampleExternalAPI.php - (multiple files) the classes that api.php loads
example.php - the file that uses the main class (api.php)
If it helps these files can be downloaded from my dropbox
api.php
<?php
/* Config */
define('pathToAPIs','API/');
/* Autoload Function */
spl_autoload_register(function($className){
$namespace=str_replace("\\","/",__NAMESPACE__);
$className=str_replace("\\","/",$className);
$class=pathToAPIs.(empty($namespace)?"":$namespace."/")."{$className}.php";
include_once($class);
});
class api {
private $listOfAPIs;
public $APIs;
public function __construct($setAPI = null){
$this->updateListOfAPIs();
if (isset($setAPI)){
return $this->setAPI($setAPI);
}
}
public function setAPIs($setAPIs){
$this->APIs = null; // clears a previous call to this method
if (!is_array($setAPIs)){ // if not an array
$setAPIs = array($setAPIs); // make array
}
foreach ($setAPIs as $setAPIType){
if(in_array($setAPIType,$this->listOfAPIs)){
$array[$setAPIType] = new $setAPIType;
}
}
$this->APIs = json_decode(json_encode($array), FALSE); // convert array of required api objects to an object
return $this->APIs;
}
public function getListOfAPIs($update = false){
if ($update){
$this->updateListOfAPIs();
}
return $this->listOfAPIs;
}
private function updateListOfAPIs(){
$this->listOfAPIs = null; // clears a previous call to this method
$it = new FilesystemIterator(pathToAPIs);
foreach ($it as $fileinfo){
$filename = pathinfo($fileinfo->getFilename(), PATHINFO_FILENAME); // removes extension
$this->listOfAPIs[]= $filename;
}
}
public function __call($method,$args){
}
}
API/exampleExternalAPI.php
<?php
class exampleExternalAPI {
public function echoString($string){
echo $string;
}
}
example.php
<?php
require_once 'api.php';
$api = new api();
$api->setAPIs('exampleExternalAPI');
$api->APIs->exampleExternalAPI->echoString('string');
Background Info
(may give some insight to my madness)
I'm working on a project where I need to connect to lots of external APIs.
So I decided to creating a class to look after all my communications with external APIs ( not sure if best way - new to Object Oriented Programming).
I'm not entirely sure what problem you're trying to solve, but if your APIs is a simple stdClass instance it should work as expected:
public function setAPIs($setAPIs)
{
$this->APIs = new stdClass; // clears a previous call to this method
if (!is_array($setAPIs)) { // if not an array
$setAPIs = array($setAPIs); // make array
}
foreach ($setAPIs as $setAPIType) {
if (in_array($setAPIType, $this->listOfAPIs)) {
$this->APIs->{$setAPIType} = new $setAPIType;
}
}
return $this->APIs;
}