Can't upload file to phalcon app - file-upload

public function profilePictureAction()
{
// Check if the user has uploaded files
if ($this->request->hasFiles()) {
// Print the real file names and sizes
foreach ($this->request->getUploadedFiles() as $file) {
// Print file details
echo $file->getName(), " ", $file->getSize(), "\n";
// Move the file into the application
$file->moveTo('files/' . $file->getName());
}
}
}
Above is the code using phalcon framework to upload image using form-data. I already test this code with postman but there is a problem.
it's output is icon-testing.png 6773
image name and image size
but file not uploaded to files folder.
already try using full path of my linux ubuntu /var/www/html/myapp/files
still can't upload.
already chmod 755 files folder
and chown :www-data and chown my-username that html folder.
If this is because bad permissions I want to know how to solve this.
Thank you.

Solved with changing Others Access: can create and delete files.

Related

NestJS Multer set dest to an url

Hello!
So, when i upload a file with nestjs and multer, i want to set the dest in the module to an url, but if i do that, then it gives me an error:
EINVAL: invalid argument, mkdir 'C:\Users\almak\Desktop\Chatenium2\chatenium-server\http:\localhost'
Can you help me why? Thanks, and also is there any way to prevent nestjs from renaming and removing the file extension from the file (test.png => 03ebe1f47494378fee61196c0524afaf )
Heres the code:
Module:
MulterModule.register({
dest: process.env.CDN_URL,
}),
Controller:
#Post("uploadImg")
#UseInterceptors(FileInterceptor("file"))
async uploadedFile(#UploadedFile() file) {
return file;
}
dest by default is a local directory for the server to access via the fs module. If you need to upload the file to another server from your server, you should use a different storage type.
As for the renaming of the file, that's also multer's default, you can pass options to the FileInterceptor according to multer's documentation to change how the file gets handled.

Laravel download from cloud storage throws file not found error

I have a file stored in an s3 bucket. I can upload fine but when I try to download using the code below I get file not found exception thrown e.g.
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "https://s3.us-west-2.amazonaws.com/mybucket/puppy.jpg" does not exist
When I navigate to the same url in a browser, the file downloads fine.
This is my code:
return response()->download(Storage::disk('s3')->url($file->path), $file->name);
Any ideas what I'm doing wrong?
This seems to work unless anyone know a more efficient technique:
return response()->streamDownload(function () use ($file) {
echo file_get_contents(Storage::disk('s3')->url($file->path));
} , $file->name);

Using prestashop app from script located outside prestashop folder

I would like to use the prestashop app from a php script (external_script.php) located outside prestashop folder but still on the same server.
I could do that with Magento using :
require_once external_folder/magento/app/Mage.php;
I've tried to include prestashop/config/config.inc.php and prestashop/init.php but it redirects external_script.php to prestashop index.php
Any help would be greatly appreciated.
STEF
Add the following 2 lines at the start of your PHP script and then you can use all the classes and functions of PrestaShop:
include(dirname(__FILE__).'/../../config/config.inc.php');
include(_PS_ROOT_DIR_.'/init.php');
Also, include the main class file whose functions you want to call in the external script, it must be some of your module's file. For example:
include_once(__PATH__TO__CLASS__FILE__.'/xyzmodule.php');
After adding the above codes to include required files you can simply create objects of the class file you want to call and use its code. For example:
$xObj = new Xyzmodule();
$xObj->callingXFunction();
Hope this helps.
Magento is a well structured Zend project and it's easy to bootstrap the app to use it outside HTTP front controller, PrestaShop is another story it's really a big mess of spaghetti code, to bootstrap the app really depends os PS version and in some cases on installed modules that changes core behaviour.
To start you can first include the config/config.inc.php file that is on PS root dir, this will init the PS classloader and a bunch of configuration defines, if you use another autoloader and a old version on PS (<1.6) you need to workaround it, this is a simple bootstrap code that allow make any PS call:
<?php
// Load PS config and autoloader
define ('PS_DIR', __DIR__ . '/../ps-wtf');
require_once PS_DIR .'/config/config.inc.php';
// I use this to load compoper dependencies
require_once __DIR__ . '/../vendor/autoload.php';
// Call old __autoload() if present, required for PrestaShop old versions
if (function_exists('__autoload')) {
spl_autoload_register(function ($className) {
__autoload($className);
});
}
// Init Shop context, required some operation will fail without it
// adust accordly to multistore PS >= 1.6
Shop::setContext(Shop::CONTEXT_ALL);
// Init PS context, some modules require that this context was initialized and with correct data
// some core function fired in the admin require at least a employee
define ('PS_DEFAULT_EMPLOYEE', 1);
$psContext = Context::getContext();
if (!$psContext->employee) {
$psContext->employee = new Employee(PS_DEFAULT_EMPLOYEE);
}
// You can make any API call
$cat = new Category();
$cat->name = [
1 => 'New',
2 => 'Nuevo',
];
$cat->id_parent = 1;
$cat->save();
echo $cat->id;
Some PS functionality depends on correct initialization of some core classes (Yes it's crazy), you can take a look at ControllerCore and FrontControllerCore to see what is happening in the normal PS request flow.
I hope that this can help.
The way prestashop is designed won't let you do this kind of thing easily.
I think your best bet is to use their web service API : http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service
There is a PHP client library for this : https://github.com/PrestaShop/PrestaShop-webservice-lib/blob/master/PSWebServiceLibrary.php
You can also use curl, but be warned : they use a lot of different tokens on differents pages, this is quite annoying.
Here is some bash code to log yourself in, grab some tokens and upload an import file. You can adapt it to PHP curl and do anything else you want :
r=$(curl -k -c cookies -b cookies -s --request POST -d "ajax=1&token=&controller=AdminLogin&submitLogin=1&passwd=[YOU_PASSWORD_URL_ENCODED]&email=[YOUR_EMAIl_URL_ENCODED]" 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php')
token=$(echo $r | sed -n 's/.*token=\([0-9a-zA-Z]*\).*/\1/gp')
admin_token=$(curl -k -c cookies -b cookies 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php?controller=AdminDashboard&token='"$token" | sed -n '0,/.*?_token=\([-_0-9a-zA-Z]*\).*/s/.*?_token=\([-_0-9a-zA-Z]*\).*/\1/p')
brand_file_name=$(curl -k -c cookies -b cookies -F 'file=#local_path_of_a_file.xlsx' 'https://[YOUR_PRESTASHOP_HOST_OR_LOCALHOST]/[YOUR_PRESTASHOP_ADMIN_DIR]/index.php/configure/advanced/import/file/upload?_token='"$admin_token" | sed -nE 's/.*"name":"([^"]*).*/\1/gp')

How to view pdf file inside the public/ folder on browser in laravel

I have pdf files inside my public/ folder lets say
public/uploads/overviews/myfile.pdf
when i try to access it on my browser like
http://localhost:8000/uploads/overviews/myfile.pdf
it is being downloaded instead to be loaded on browser.
How can I load the pdf file on the browser without getting downloaded by the user?
You may use the following PHP code for view the PDF files:
View File
And the view.php page has the following code:
<?php
$path="uploads/overviews/myfile.pdf";
header('content-type:application/pdf');
echo file_get_contents($path);
?>
Add following line before your link -
Example -
<object data="myfile.pdf" type="application/pdf" width="98%" height="80%">
...view Myfile..
Try the below code :
return Response::make(file_get_contents('uploads/overviews/myfile.pdf'), 200, [
'content-type'=>'application/pdf',
]);

Node-webkit app- how to update it?

I am using node-webkit to develop apps for my students, and to provide one stop solution I would need to update node-webkit archive once in a month. Is there a way I can accomplish that?
Basically I need to replace just one html file every month, say "page1.html".
I googled but have no idea where to start.
On Mac, you can access the filesystem of the own app e.g.
$ ls -lh /Applications/Shock.app/Contents/Resources/app.nw/
[...]
-rw-r--r-- 1 jordi staff 2,3K 29 gen 01:47 index.html
-rw-r--r-- 1 jordi staff 467B 29 gen 01:47 lecturenotes.html
[...]
So if you put a new version on a specific URL, you could fetch it and rewrite the HTML file inside the app:
var request = require('request');
request('http://www.your-own-server.com/app/lecturenotes.html', function (error, response, body) {
if (!error && response.statusCode == 200) {
var fs = require('fs');
fs.writeFileSync('/Applications/Shock.app/Contents/Resources/app.nw/lecturenotes.html', body);
}
});
I think something similar happens on Linux. Unfortunately, the Windows version works with a binary package into the exe, so this trick won't work for the last case.
I have used App.dataPath as described in https://github.com/nwjs/nw.js/wiki/App
You can download the html files into that path. App.dataPath works platform independent , though the location is different based on the platforms , your app will have a generic path to refer the html files.
excerpt :
Get the application's data path in user's directory. Windows:
%LOCALAPPDATA%/; Linux: ~/.config/; OSX: ~/Library/Application
Support/ where is the field in the manifest.