prepend windows network drive in php/linux - php

=> I have network drive F. Its on windows currently which I want to communicate in linux. I know first mapping needs to be done before I can call in the code.
=> The path for F drive looks like this F:\AB. (The same path is in the db as well)
I know I need to prepend with something because there is a mount before I can call in the code in my linux environment. (prepend to the db path)
Current php code:
<a href="'.$test['QWERTY']['FILE_PATH'].'"\"'.$test['QWERTY']['FILE_NAME'].'">
This is what I have tried:
<a href="'.$linux_file_path.$test['QWERTY']['FILE_PATH'].'"\"'.$test['QWERTY']['FILE_NAME'].'">
Problem Statement:
I am wondering if I can hardcode the linux file path or it will change depending on the situation.

Related

Display image with absolute path on Winows with PHP's built in server [duplicate]

I'm loading a html file hosted on the OS X built in Apache server, within that file I am linking to another html file in the same directory as follows:
<a href="2ndFile.html"><button type="submit">Local file</button>
This works. However (for reasons too lengthy to go into) I am experimenting using the file: scheme instead, however I cannot get anything to work. Here is how I am re-writing the above line using file:
<a href="file://192.168.1.57/~User/2ndFile.html"><button type="submit">Local file</button>
(192.168.1.57 is my current IP address)
Changing it to the following does also not work:
<a href="file://Name-Of-MacBookPro/~User/2ndFile.html"><button type="submit">Local file</button>
But the file cannot be found, how should it be specified using the file: scheme?
The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows).
Many browsers, for security reasons, do not allow linking from a file that is loaded from a server to a local file. So, you may not be able to do this from a page loaded via HTTP; you may only be able to link to file: URLs from other local pages.
the "file://" url protocol can only be used to locate files in the file system of the local machine. since this html code is interpreted by a browser, the "local machine" is the machine that is running the browser.
if you are getting file not found errors, i suspect it is because the file is not found. however, it could also be a security limitation of the browser. some browsers will not let you reference a filesystem file from a non-filesystem html page. you could try using the file path from the command line on the machine running the browser to confirm that this is a browser limitation and not a legitimate missing file.
The 'file' protocol is not a network protocol. Therefore file://192.168.1.57/~User/2ndFile.html simply does not make much sense.
Question is how you load the first file. Is that really done using a web server? Does not really sound like. If it is, then why not use the same protocol, most likely http? You cannot expect to simply switch the protocol and use two different protocols the same way...
I suspect the first file is not really loaded using an apache http server at all, but simply by opening the file? href="2ndFile.html" simply works because it uses a "relative url". This makes the browser use the same protocol and path as where he got the first (current) file from.
I had similar issue before and in my case the file was in another machine
so i have mapped network drive z to the folder location where my file is
then i created a context in tomcat
so in my web project i could access the HTML file via context
For apache look up SymLink or you can solve via the OS with Symbolic Links or on linux set up a library link/etc
My answer is one method specifically to windows 10.
So my method involves mapping a network drive to U:/ (e.g. I use G:/ for Google Drive)
open cmd and type hostname (example result: LAPTOP-G666P000, you could use your ip instead, but using a static hostname for identifying yourself makes more sense if your network stops)
Press Windows_key + E > right click 'This PC' > press N
(It's Map Network drive, NOT add a network location)
If you are right clicking the shortcut on the desktop you need to press N then enter
Fill out U: or G: or Z: or whatever you want
Example Address: \\LAPTOP-G666P000\c$\Users\username\
Then you can use <a href="file:///u:/2ndFile.html"><button type="submit">Local file</button> like in your question
related: You can also use this method for FTPs, and setup multiple drives for different relative paths on that same network.
related2: I have used http://localhost/c$ etc before on some WAMP/apache servers too before, you can use .htaccess for control/security but I recommend to not do so on a live/production machine -- or any other symlink documentroot example you can google

Symfony finder, Ignore dot files doesn't work with FTP address

I'm using Symfony, and the component Finder. I want to get a file whose name begins with dot (".file.txt") and this file is in other server.
If I do this:
$finder
->files()
->ignoreDotFiles(false)
->in("ftp://user:pass#exmple.example:/myDir/")
;
I don't get any file but, if I rename the file and remove dot
("file.txt") then I can find it.
If I try to find files that start with dot in my local computer then
it finds it well. Like here
So my question is: Why the method ignoreDotsFile doesn't works when is ftp address?
The code is very simple and clear, so if does not work is by a bug of Finder + FTP component.
In fact FTP causes a lot of bugs like these:
Options not working
Bad performance
More
If connects with a windows machine this code would work fine but the problem was with linux server.
Answer provided by: Javier Eguiluz

How do I get PHPStorm to use the correct path for CSS?

I have been using "Delphi PHP XE2". The file structure has worked fine for over a year on the development machine and the production.
The folders are organised as follows.
src/app_login.php
src/add
src/css
src/js
src/fnc
src/db
src/images
etc.
I am just trying out PHPSTORM. The include files work fine. When I run it in Firefox it can find all images, JavaScript files, etc. But it can not find the CSS files as it is looking for them in
css
rather than
src/css
I haven't changed anything.
Why is the browser now looking at absolute path rather than relative?
How did PHPStorm manage to tell it that?
And how do I coerce it to treat them as relative paths?
I see that in the browser it runs it as:
http://localhost:63342/SRC/app_login.php
instead of
http://localhost:63342/app_login.php
I guess this the problem. How do I coerce it to move down one directory level?
I am trying to set up IIS, I think this might be best for later on. Here are the screen shots:
I configured the hosts file so that when I type wys.com in the browser it tries to run it and shows a blank page. If I type in 192.168.1.0 it just shows a blank page. View Source shows nothing. I was expecting it to run the index.html at d:\wys\src. Why is the browser not running it?
You are using PhpStorm's own simple built-in web server which uses URLs like http://localhost:63342/ProjectName/app_login.php. You cannot make http://localhost:63342/app_login.php using such server as it will not be able to tell what files to serve.
Either use your own Apache/IIS/whatever web server .. or the best you can get with built-in server would be http://ProjectName:63342/app_login.php(IDE needs to know what site/files to serve somehow). For that:
Edit your hosts file (or local DNS server, if preferred and have one) and point ProjectName to your computer's IP (e.g. 127.0.0.1).
Create Deployment entry of correct type (In Place should do), configure it (provide desired URL etc -- http://ProjectName:63342/) and mark it as Default for this project -- now IDE will use URL from there when generating "open in browser" URLs.

PHP How to set a path to a Virtual Directory in IIS Windows 8.1

I have recently set up IIS on Win 8.1 machine to run a server for my small perosnal requirement.
I have a lot of e-books saved in "%SystemDrive%\Users\admin\Google Drive\phpbooks" folder. I have recently found a way of dynamically indexing all my-ebooks in a catalog which I can then access from www. The program that does it is a php program running on iis.
Scenario 1:
When I copy and paste all my books from the above location to %SystemDrive%\inetpub\wwwroot\Books, this php program is able to locate the metadata file when I use this command:
"$config['calibre_directory'] = array ("Fiction" => "/inetpub/wwwroot/phpbooks/F7N5/", "Non-fiction" => "/inetpub/wwwroot/phpbooks/NF7N5/");"
in config_local.php file of the php app that I am using.
It is working fine, but the problem is that both the server and google drive folder are sitting on the same hard drive. Which means that I am duplicating the data.
This is what I am hoping to achieve:
Scenario 2:**
Create a virtual drive of the main google drive folder within IIS wwwroot folder. Change this command in config_local.php:
"$config['calibre_directory'] = array ("Fiction" => "/inetpub/wwwroot/phpbooks/F7N5/", "Non-fiction" => "/inetpub/wwwroot/phpbooks/NF7N5/");"
to a command which can correctly help this php program find its way to the google drive through the OS.
However, since I am not a php champion I don't know what syntax or command or script or code to use that will help point this program to the exact location of where the books are originally without the need to duplicate data on a server folder.
I hope I have been able to explain my issue clearly and comprehensively to you. Your help will be highly appreciated.
Many thanks.
Kind regards,
Rishi Saran.

what is the difference of absolute path in html and php?

I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp.
now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html'); it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it works perfectly and opens the file. below is my test code
<?php
echo 'headerfile';
include('/template/header.inc.html');
?>
if I give the full path for example C:/wamp/www/template/header.inc.html to the include function it works fine.
I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost
I would appreciate any help that would clarify my confusion, Thanks.
Absolute paths on the server start from the server's hard disk (C:\).
Absolute paths on the client start from the root of the website (http://example.com/).
You can make use of __DIR__ to make some file on disk relative to the php-file on disk itself:
include(__DIR__.'/template/header.inc.html');
This should solve your issue.
The difference is not that easy to explain because both types of paths - even related - are two pair of shoes. I suggest you start with a very basic HTML website tutorial that explains how to link on your website and where files are located and how that is related to the webserver configuration.
HTML pages live in the client's browser that know nothing about your server's folder structure, and they're relative to the domain name eg. http://example.com/.
PHP programs run on the server side and they deal with the server folders. You shouldn't hardcode full paths in your php programs, because it will cause problems whenever you'll move them between the development server and the live host (just to name an example). Therefore in php files you should either use relative paths to your file, or use the __DIR__ magic constant that gets substituted with the directory where the php file is.
1.) First approach: include('template/header.inc.html');
2.) Second approach: include(__DIR__ .'/template/header.inc.html');
In your case (working on a development machine) both the client and the server is the same box, that might be confusing you.

Categories