how to access the file with modified url in php? - php

I want to access a file with my modified url without going via .htaccess
Let assume my file is in
root/newfolder1/xyz.php
So the url below is working fine
www.abc.com/newfolder1/xyz.php
I want to access the file in newfolder1 but with modified url like below:
www.abc.com/xyz.php // This I want but it is not working.
Any ideas or suggestions would be welcome.

You can either use symlink
Or you can make a php in your main folder
xyz.php
And include the php inside the newfolder1/xyz.php
Using this method make sure to change working dir to newfolder1 before including.

Related

PHP file handling and third level domains

I've a subdomain like software.domain.com that is a redirect to domain.com/software/ through cPanel redirect.
I'm creating an upload system that send all the files in a sibling folder, like domain.com/files/, no problem uploading with some tricks but when it's time to delete that file, that specific script cannot find it...
Returning the $_POST variable send to the script, the path is right, as /files/path/to/file, it refers to the public_html root as it has to be!
The script is invoked using an ajax call, it could be it? Maybe some path translation...
Thanks a lot!
If you are saying your AJAX can't find it from the subdomain, or anywhere else, you need to use the full domain path, WITHOUT the subdomain.
var url = "http://domain.com/files/path/to/file";
If you're saying your PHP can't find it, you can do something like this to ge the absolute path. From a file in the root of your SUBDOMAIN...
$url = realpath(dirname(dirname(__FILE__)))."/files/path/to/file.php";

Including a php file from a parent directory

I have a user_ip_location.php file in "/user/files/new" folder.
full url to the file is
/user/files/new/user_ip_location.php
I want to include this file to profile.php file that is located in Root dir
I have tried the following code
include("/././user_ip_location");
and
include("http://example.com/user/files/new/user_ip_location");
Both are not working, first is returning no such file or directory and the second is not loading the page and the browser is returning error could not locate to remote server
Is there any way to fix it?
You need to indicate previous directory by double dots ..
include("../../user_ip_location.php");
If I understand your question correctly you are in some directory and want to include a file from /user/files/new/user_ip_location.php. So just including it by specifying the path should do the trick.
In your example this would be:
include("/user/files/new/user_ip_location.php");
If the file you want to include is levels above your current directory just specify this by using .. like include("../../user_ip_location.php");
Try this:
include './files/new/user_ip_location.php';

Issues while importing php files

I am developing a website on a local test environment. From time to time I need to import classes or functions into my php pages. At first I used relative paths to import files, but for some (unexplicable) reason the PHP couldn't find those files. So I have thought it would be necessary use the following:
<?php require_once($_SERVER['DOCUMENT_ROOT'] .'/mywebsite/inc/libs/functions.php'); ?>
The problem is when I have to upload all the pages to my remote webserver, the PHP interpreter won't find functions.php in that position because there is no mywebsite subfolder , on the other hand I can't get rid of mywebsite subfolder, because that would leave me with http://localhost/inc/libs/functions.php which leads nowhere.
So that basically means I will have to manually readjust the path to make everything work. My question is: is there a way for PHP to detect the exact folder of my website so that I don't have to change paths everytime I need to upload a php file to my webserver?
What is the reason behind impossibility of use relative path?
<?php require_once(dirname(__FILE__).'/inc/libs/functions.php'); ?>
Set the base folder with all the files you want as an include path in php.ini.
That way, when you use include () or require (), it will automatically look in the included path.
www.php.net/manual/en/ini.core.php#ini.include-path

One web page with multiple URL's using PHP

I was wondering how you could make it so that "website.com" has an index.php file that simply opens "website.com/home" but without changing the URL. I originally had it so that it used a PHP include of "website.com/home/index.php" inside "website.com/index.php" but when i had to use includes inside of "website.com/home/index.php" it stopped working as it was running the includes from "website.com/index.php" instead of "website.com/home/index.php" is there any way to simply send the file "website.com/home/index.php" and have it run from "website.com/home/index.php" without changing the URL? I would want to avoid having to use the absolute location to simplify it and so i can copy and paste the code into other directories without having to edit it accordingly.
Use chdir() to navigate to the correct folder, then include("index.php");

interesting characters in URL in joomla

i have a URL that looks like this
......index.php?option=com_jumi&fileid=8&Itemid=34
i know that i can view the source of the file just by view source from the browser, but since i have FTP permission for the site, i would like to be able to edit the file.
but i dont know which file to edit!
how do i find out which file is this link going to so that i can access it through ftp?
It should be here:
Root Joomla Folder -> Components -> com_jumi
Now inside the com_jumi folder, it depends which file you want to edit, for example there you will find the file for current pages looks (View), a file with database queries (Model) and a main logic file called controller. You have to decide which file you want to edit.
Note: inside the com_jumi folder, the files can be inside other folders too, you will have to find out which file you want to edit.

Categories