Correct file path when using move_uploaded_file()?

I have created a simple file upload script that works on my localhost - it allows the user to upload a file and then store it on a directory on my PC. The script includes the following function:

move_uploaded_file($file_array['tmp_name'],
			"$file_dir/".$file_array['name'])

When $file_dir = “C:\\xampp\\htdocs\\forms\\files”; the script works fine.

However, when I upload the script to the web on mydomain.com, I can’t get it to move the uploaded file to a directory at mydomain.com/files. I’ve been using options such as the following for $file_dir

= “/files”
= “files”
= “mydomain.com/files

but none of them work.

Can you please tell me what I need to set $file_dir = to, in order to get the move_uploaded_file() to work?

Many thanks!

Try using $_SERVER[‘DOCUMENT_ROOT’] .‘/tmp’;

Thanks a lot for your reply John. I tried that, but could not get it to work. However, by playing around with it I managed to get the file upload script below to work. (I’m aware that it has no security protection, so I haven’t left it online, until I learn more about how to do that.)

<?php
	
	$file_dir = "files";

	foreach($_FILES as $file_name => $file_array) {
		echo "path: ".$file_array['tmp_name']."<br />\
";
		echo "name: ".$file_array['name']."<br />\
";
		echo "type: ".$file_array['type']."<br />\
";
		echo "size: ".$file_array['size']."<br />\
";
	
		if (is_uploaded_file($file_array['tmp_name'])) {
			move_uploaded_file($file_array['tmp_name'],
			"$file_dir/".$file_array['name'])
			or die ("Couldn't move file");
			echo "File was moved to: <a href=\\"http://mydomain.com/files/".$file_array['name'].
				"\\">http://mydomain.com/files/".$file_array['name']."</a>";
		}  else {
			echo "No file found.";
		} // else
	} //foreach

	?>

Thanks again John, although I didn’t directly use your suggestion, it was by trying it out that I managed to get the script to work.