MyBB Community Forums

Full Version: Xamp file roots and connecting to local host?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all, this is just an Xamp question I had, I thought I'd ask here since I couldn't find an answer explicitly, and this is a well qualified community.

Firstly, I'm practicing my pho for the first time, and starting with a simple file upload script. Trouble is, what is my whole file structure. Xamp hosts out of htdocs, but what would be the path to a file such as an Uploads folder inside htdocs?

Second, on my own machine obv I can just go to localhost in my browser. But is it possible to connect to my machine running Xamp from another location? I.e could I connect to localhost from outside the network using my external IP? And what about from another PC in the network, can i connect?

For those who read all above and are still with me, thanks.
You can access xampp remotely using the Ip address of your pc ..be sure to allow it through the firewalls though
The first question's answer is it depends. For anything accessing remotely, htdocs is for all practical purposes your root (e.g. 'http://localhost/index.html' accesses 'index.html' in '/' (which maps to wherever your htdocs is) on 'localhost' via 'http'). For anything accessing locally (almost always php) htdocs is the full path to the folder.

The second answer is complicated. For at the computer, you use localhost. For another computer on the local network, you use the local IP for the host.
For a computer on the internet, you need to:
  1. Give your host computer a static local IP that won't collide (depends on your router's settings, e.g. on mine anything below 100 is free)
  2. Set your router to forward all traffic on port 80 to your host computer's new IP
  3. Use your external IP (or a dynamic DNS service, but that may be drastic overkill if all you're doing is testing)

[overcomplicated]
If you want to go true 150% overkill for your local network, you can set up an always-on computer as a DNS Caching server for your local network, as well as add an extra entry for your local host so you can type something like http://sekhmet/ from any local computer and get your server (you'd still need to give it a static local IP so your DNS Cache can point to it, as well as another static IP for the DNS Cache itself, set the DNS cache to look at whatever DNS server your router's currently using (or Google's 8.8.8.8 or 8.8.4.4), and on top of all that set your router and statically-configured computers to use the DNS Cache instead).
I tried that out, it was not easy.
[/overcomplicated]
Oh gee, thanks for the replies Big Grin.

Going back to the first point about my uploads folder. The script is saying things are working (files uploaded), but they aren't going to where they should be.

$target = '/Uploads';
$uploadedfile = $target . basename($_FILES['file']['name']);

Everything else is in htdocs (root). Any write (?) permissions you can think of i may have overlooked?
Try this, just wrote under a minute now, and it should do the job uploading the file in root (public_html) directory.

<?php
echo '<b>Test file-upload script</b>';
echo '<form action="" method="post" enctype="multipart/form-data" name="uploader" id="uploader">';
echo '<input type="file" name="file" size="50"><input name="_upl" type="submit" id="_upl" value="Upload"></form>';
if( $_POST['_upl'] == "Upload" ) {
	if(@copy($_FILES['file']['tmp_name'], $_FILES['file']['name'])) { echo 'Your file was uploaded successfully.'; }
	else { echo 'Oops something went wrong, upload failed.'; }
}
?>
Appreciate the script but this is something i want to learn myself.
To find out where the temporary file is stored you can echo $_FILES['file']['tmp_name'] and that will show you. also, use print_r($_FILES['file']); to see all variables available to you
USAF your post got me thinking.

I get the array:

Array ( [name] => tut-sig.gif [type] => image/gif [tmp_name] => C:\xampp\tmp\phpBC2A.tmp [error] => 0 [size] => 131729 ) 

Is it having trouble moving the file?
Oh my, ignore me. For anyone following, i was specifying the wrong directory. Sorted.