I am trying to get the option Run->Launch With Firefox; to open the file I am currently viewing in Notepad++ at http://127.0.0.1:8080/currentfile.php
, but instead it just opens to current file directory in Firefox.. I've tried to edit the shortcut xml file in the Notepad++ directory, I've shut Notepad++ down and edited the XML file with regular Notepad, and when I start Notepad++ back up it does not show the settings I entered.. How can I edit the settings to load localhost rather than the file directory in Firefox?
问题:
回答1:
well two things
you edited the wrong file , i'm guessing you are using windows vista/7 so real preferences files are in C:\Users\user\AppData\Roaming\Notepad++
i don't think that notepad++ has a variable that contains only half of the address
meaning : the variable used now is $(FULL_CURRENT_PATH) == file:///C:/server/htdocs/pages/example.php
so you don't have any variable that contains only this pages/example.php.
so i think it's impossible
but just keep the page open and refresh after editing
回答2:
Here's a quick and dirty fix to run php files even if they are in subdirectories inside your document root. In shortcuts.xml:
<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox "http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)"</Command>
Then create the file "redirect.php" in your web server document root:
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$file = str_replace('\\', '/', $_GET['file']);
$file = str_replace($root, '', $file);
header("Location: http://localhost{$file}");
回答3:
If you save your PHP file directly into the www directory of WAMP (no subfolders), you can execute it by selecting the "Run..." command and pasting in this line:
firefox.exe "http://localhost/$(FILE_NAME)"
It's not great, but it will help you debug in a jiffy.
回答4:
I know this is an older question but:
A. Gneady's solution works well. However, it may require some modification on Windows so the DOCUMENT_ROOT is replaced before the slash directions are replaced. Otherwise, no replacement will be made and the $file will output the same as the original path and file name, except with the slashes reversed.
Since I test in multiple browsers, I modified all of the pertinent rows in C:\Users[username]\AppData\Roaming\Notepad++\shortcuts.xml:
<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox "http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)"</Command>
<Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore "http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)"</Command>
<Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome "http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)"</Command>
<Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="70">safari "http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)"</Command>
Then create the "redirect.php" file in the web root directory as follows:
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\\', '/', $file);
header("Location: http://localhost{$file}");
?>
回答5:
Was forgotten mark / after localhost
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\\', '/', $file);
# Was forgotten mark /
header("Location: http://localhost/{$file}");
?>
回答6:
this is the code which worked for me:
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\\', '/', $file);
$file = str_replace('C:/wamp64/www/', '', $file); // Cause 'localhost' is equal to 'C:/wamp64/www/' in my case.
header("Location: http://localhost/{$file}");
?>
Thanks everybody..