0

This question already has an answer here:

I have upload.php file in magento2 root folder.

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

marked as duplicate by Murtuza Zabuawala, Manashvi Birla, liyakat, Manoj Deswal, Priyank Jul 2 '18 at 10:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • want to include this file from another file or your want to call this url – Amit Bera Jul 2 '18 at 9:43
  • I want to call directly form magento2 root folder – Rutvee Sojitra Jul 2 '18 at 9:43
  • Why would you want this? – vitoriodachef Jul 2 '18 at 9:46
  • I want my custom script there for perform custom functionality – Rutvee Sojitra Jul 2 '18 at 9:48
  • have you tried with a die in the end of file? – Gagan Jul 2 '18 at 9:51
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(); 
?>
  • Not working !!! ithink it's need any htaccess rule – Rutvee Sojitra Jul 2 '18 at 9:51
  • NO htacsess needed for script, it's custom script i'm using. May be your store not configured well prntscr.com/k1jbfe – Ketan Borada Jul 2 '18 at 9:53
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.

  • Not working !!! have tried – Rutvee Sojitra Jul 2 '18 at 9:46
  • Are you using Apache or NginX? – Greg Jul 2 '18 at 9:52
  • apache @Bare Feet – Rutvee Sojitra Jul 2 '18 at 9:57
  • Updated the answer. – Greg Jul 2 '18 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.