0

I have upload.php file in magento2 root folder.

How can i access directly www.example.com/upload.php directly in magento2?

Rutvee Sojitra
  • 3,881
  • 2
  • 17
  • 55

2 Answers2

2

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(); 
?>
Ketan Borada
  • 2,603
  • 2
  • 33
  • 77
0

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.

Greg
  • 2,929
  • 4
  • 39
  • 84