I have upload.php file in magento2 root folder.
How can i access directly www.example.com/upload.php directly in magento2?
I have upload.php file in magento2 root folder.
How can i access directly www.example.com/upload.php directly in magento2?
Create upload.php file in your magento root folder
<?php
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
echo $baseUrl= $storeManager->getStore()->getBaseUrl();
?>
The root of Magento 2 is http/pub/.
So if you upload you file there, you should be able to access it via www.example.com/upload.php
If you want to keep the file in /http/ directory and still access it, you can do it in NginX (if you use NginX). Something like this would do the trick:
# upload.php
location = /upload.php {
alias /full/path/to/your/magentoproject/http/upload.php;
}
PLEASE NOTE execution of PHP files might be restricted when trying to access the file inside of the pub directory. If you want to execute the file from inside the PUB directory, try adding something like this:
location ~* \.(php) {
include fastcgi_params;
}
UPDATE:
If you are using Apache, try following:
alias "/upload.php" "/full/path/to/your/magentoproject/http/upload.php"
And reload your Apache services.
upload.phpin pub folder – Murtuza Zabuawala Jul 02 '18 at 09:56