I'm trying to navigate to C drive via PHP on my local drive, this one line of code works fine:
<a href='<?php echo'file:///C:\Users\Emily\Documents\'?>' TARGET="_blank" >Clcik Me</a>
This works fine from my local drive but as soon as this is on my sever it throws an error. I've been trying to strip and replace slashes but to no luck, hope sone one can help me.
This is because on the server there is no "C:\Users\Emily\Documents".
You need to make sure that the filepath you use is available to you on the server. My recommendation would be to setup your local machine to have the same filepath which exists on your server.
For example lets say you have a folder named Web, in which you keep the following files and folders:
index.php
\images (This is another folder)
From your file if you wanted to access a file in the images folder, from your index.php file you would access it as "images\FileYouWant.jpg"
Your server should have the same setup so you copy index.php and the images folder into the folder on your server, this way they keep the same file paths.
You can find more on file paths here
you can't access local file links from remote servers. if that were still possible (Like it was many years ago), a remote site could get at your local files...
Your server OS maybe not windows and file path is different!
Try to debug with <?php var_dump(real_path('file_path.php')); ?>
Related
I have saved a PHP file to my Applications/XAMMP/htdocs directory and I want to run it in a browser.
I have used all sorts of url combinations including:
http://localhost/xammp/htdocs/HelloWord.php
http://localhost/xammp/HelloWord.php
amongst others and I cannot find the right url.
I am using XAMPP on a Mac Majove.
If you installed the XAMPP VM version, then you can probably access it via http://192.168.64.2/HelloWord.php (check the General tab in the XAMPP app for the IP address)
If you installed the native version, then I guess it is
http://localhost/HelloWord.php
The htdocs/ folder is the document root. Its content is served under the server address. Neither the xampp nor the htdocs folder will be part of the URL. The paths are relative to the document root, and you shouldn't be able to access parent directories above htdocs/ (although server-side code such as PHP has access to the file system and may work with files outside of the document root).
First of all, expecting the php file to have information that can be visualized in a web browser, inside xampp if you have the .php file in the htdocs folder you should be able to visualize it like this:
http://localhost/HelloWord.php
Found it by trial and error, quite different from what I took from various instructions on line:
http://localhost/HelloWord.php
XAMPP's default root should be "htdocs" or "www". Put your PHP files into those folder and try again.
if it is not work, find the configuration of Apache and PHP in XAMPP folder.
I have Synology DS1515+ and I've installed Web Station with Apache and PHP on it. I have web directory (full path /volume1/web) in which I can host webpages.
I have PHP file with tag video in which I would like to have video from video directory (full path /volume1/video).
So in web directory in PHP file I have something like below, but video file isn't hosted:
<video id="video" autoplay>
<source src="/volume1/video/movie.mp4" type='video/mp4'>
</video>
I also tried related path like '../video/movie.mp4' but it also doesn't work.
I read this question: Access synology shared folder from PHP and I edited open_basedir but it took no effect.
Thanks for help.
Your src needs to be relevant to the apache path being served.
E.g. if apache is serving content from /volume1/website/public_html your source is relative to this folder. You won't be able to break out of this to get to /volume1/video/movie.mp4 either.
Try looking at apache getting started here https://httpd.apache.org/docs/trunk/getting-started.html
Some will no doubt go on to voice their concerns - and normally I'd say rightly so.
However, goto Web Station, click on PHP Settings, select PHP version and add /volume1/video/ to the end of open_basedir, i.e. add :/volume1/video/ paths are split by a :
I do similar to serve photo's from outside the web root. I then have a PHP script to fetch the file required from /volume1/photo (in my case). and use like src="getfile.php?name=file.jpg" which can access the file you want and provide it. Bit of a workaround but it works.
All the servers are running correctly in XAMPP, and I when I run http://localhost the XAMPP page comes up. However when I try to run a php through xampp by accessing the directory where the file is stored, i.e.,
http://localhost/Applications/XAMPP/xamppfiles/htdocs/gallery.php
I get error 404. I've tried loads of different paths, but here is the path to the file in finder path image
Any ideas?
Thanks!
your webserver is resolving the domain localhost to a specific directory, the so called document root. (this can be adjusted in your server config). I would assume that it points to /Applications/XAMPP/xamppfiles/htdocs. so your file should be accessible via
http://localhost/gallery.php
I have deployed my PHP web app on Amazon Ec2 cloud , but my files are not running ,because my my files's are uploed using ec-user account while if i create a file there using root it can run easily.
i have changed the owner and group of all uploaded files to root , but then also server response is
The website encountered an error while retrieving mydns/index.php It may be down for maintenance or configured incorrectly.
while if i run another file which i create there using putty then it runs perfectly.
Please help me if u think a some configuration is required there
I have deployed the website there inside /var/www/html/somefolder/
check the permissions of a .php file which is working and one which isn't with ls -l. I believe the permissions need to be 744.
Unix is case sensitive while Windows is not when i am referring any files in case sensitively the PHP gives error in Unix only so, to make it woking I need to make all paths and file referencing like
various include ,require,src and action varible and methods case sensitive.
Thanks to all of you.
i'm using Xampp. When I tried to do this earlier, it worked, but now it is not working.
I'm trying to make a directory in my www folder to hide it from baddies who steal files.
Each user gets their own folder in uploads to put their files on.
Xampp uses apache, and Xampp is a local web server. It allows me to design websites without the need of an online host. The www folder is in my C:\program files\xampp\php\www\ and I need to make a directory there. I know it's possible because i've done this before, I have just forgotten how to make it happen.
When I make a directory I use:
$uploaddir1 = "xampp/php/www/uploads/".$esclcusername."/";
mkdir($uploaddir1,0777);
Do I need to include C:\program files\ before xampp?
And finally, how would this be possible on a real online web host?
I saw your question here and searched some on google. This is what i found:
mkdir("D:/hshome/rubygirl58/gameparody.com/clansites/".$sitename."/lib", 0777)
So yes, I think you have to include the complete path.
Greetings,
Younes
you need to make sure that you give permisions to the parent folder to create dirs in it (0777)
to get the full path you can use dirname(FILE) wich will return the path for the directory of the file in wich it is runned