Get remote path of current location - php

I am making a reseller hosting, for my own clients, but now I want to store my user-backups on a different host. So use a cronjob to do this.
But now my cronjob asks me for a Remote path to store the backups on.
I just want them in the /backups folder, but I guess I can't just fill in /backups in the remote path?
So how can I see what the full pathname is?
My idea was to create a .php file, and echo the remote path with some code.
I can't find the code on the internet so I asked it here.

If you need a path of a other machine with PHP, then thats do the trick:
echo __FILE__; // Full Filename
// OR
echo basedir( __FILE__ ); // Only the Path

Related

How to get client side absolute path of selected file in php

I want to know whether there is anyway to get the client side absolute path of selected file!
$_FILES['xml_file']['tmp_name']; This also provides path of selected file but its server side path... Its result is something like this C:\xampp\tmp\php2679.tmp
I want C:\Users\Sami\Desktop\data\myfile.xml where my actual file is placed.
Because I want this actual path to use again for fetching and saving etc automatically (by code).
you may try echo realpath($_FILES['xml_file']['name']); on your php.
then the output will be:
C:\Users\Sami\Desktop\data\myfile.xml
When you click the browse button it chooses the file. When you click the submit button, the entire file is being sent from the browser to the web server, and PHP is indeed putting the entire file in the php servers temp directory. Then, your script gets called.
So when you try to get absolute path from $_FILES['xml_file']['name'] or $_FILES['xml_file']['tmp_name'] or realpath($_FILES['xml_file']['name']) you will get the path on server.
The solution to this problem would be to simply copy the file somewhere, and not ask for the file upload again. You'll need to be sure that where ever you copy it to on your web server, that the server has permissions to do so. Usually that involves giving write permissions for the user which the web server runs as (usually user 'apache' or 'nobody' for apache based servers) to a special directory you've created for the purpose.
Copy is available in PHP. http://us3.php.net/manual/en/function.copy.php
Your only trick will be what to name it so you can find it again for the second request, and deciding what directory to put it into.

This path for a picture doesn't work

I'm building graphs using pChart in PHP. The case is that I have my picture in the right folder, I know it because if I put that path in the browser I can see my picture, but in the template, it doesn't show up. Firebug shows "failed to load the given URI".
<img src="/home/user1/mysite/Admin/Template/mx_graphs/example13.png">
The picture has all the rw permissions given, and the folder.
You appear to be using a UNIX file path instead of a relative URI. Your web server is unlikely to be configured to have the DocumentRoot be / (and it would be very silly to do so).
Construct a URI relative either to the HTML document or to the DocumentRoot of your server.
The latter will probably be /Admin/Template/mx_graphs/example13.png
Remember the statement:
<img src="/home/user1/mysite/Admin/Template/mx_graphs/example13.png">
Will run on the client side, so if you run this on the very computer where the picture is stored, it should work fine, but if you try to open it from another computer it will not work.
Try to use relative path (http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/), and try to keep the website resources into the website root folder, so that even when you host the site the image be copied over and will still be accessible..

Access to client's localhost from server

Here is the context : I need to load heavy files in the Google Earth plugin on a website. I have a php script that build up a path to those files and send it to javascript through ajax. Then, the plugin download the file and build it on earth. This take a long time. I need to speed that up for a public event. The computer can run a web server and have these files on his hard drive.
So here is my question : Is there a way for php to check if the client is running a local server and check if it contains a specific file ? Or at least, to execute a php script from this local server ?
Something like :
if(is_file('localhost/files/heavy.kmz'))
$path = 'localhost/files/heavy.kmz';
else
$path = 'www.randomsite.com/files/heavy.kmz';
return $path
Of course, this localhost refers to the wrong server :(.
I guess that if it was possible, there would be security issues. But i ask anyway.
I'm not very used to stackoverflow habits, I hope a didn't do anything wrong.
Kororo.
Edit : I will try to clarify a bit.
I know the path of the files on localhost. I need to check if it exist or not in order to send a path or another. If i can find it, i don't have to download it from the server.
The local webserver is only needed on machine to allow php check of the file.
If the data file is on the same machine, and you can tell where your data file should be relative to the script you are using to check it's existence, just use the __DIR__ (or dirname(__FILE__) if your php is ancient) to create the path.
So for example, you have have the directory structure like this:
files/
heavy.kmz
check.php
...
Then inside the check.php the following work as expected:
if (is_file(__DIR__.'/files/heavy.kmz')) {
$path = __DIR__.'/files/heavy.kmz';
} else {
$path = 'www.randomsite.com/files/heavy.kmz';
}

file_put_contents could not store image on server

$path = 'http://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc6/372096_100002534902767_1927052265_n.jpg';
$info = file_put_contents('new/angel.jpg', file_get_contents(urldecode($path)));
echo $info;
It works fine on localhost but it did not work on my website.
Any idea what the problem might be?
Check your logs for error messages
Does the folder ("new") exist?
Are permissions set to allow writing by scripts?
Are you sure the error is in file_put_contents? file_get_contents could fail if the host has disallowed url_fopen.
unless $path is actually hardcoded, you will probably introduce an arbitrary file disclosure security issue. Make sure you validate your input.
you need to give a permission (write ) to upload folder
you can do that by the FTP program by using this codes in numeric value :777
Make sure that there are write permissions to the file in which you are writing
I think the relative path is the problem. It can possible that your local has the path to that file but the path does not exists on server.
3.Please put a forward slash in line $info=file_put_contents('new/angel.jpg', file_get_contents(urldecode($path))); before your "new" folder and try i think this might be a problem

PHP File Upload Directory

I am working on a file upload script. I know that every part of the script is valid, except for the path I am trying to specify.
I am not exactly sure what the path should be relative to. Does it need to be relative to the temporary folder that PHP stores the file in, or relative to the location that my script is running from?
Also, I'm not sure how specific I need to be. The directory where I am trying to upload the file is: www/mm/uploads
It would be relative from the location that the script is running from.

Categories