troubleshooting Question

Full url path for uploaded file - PHP

Avatar of QuintusSmit
QuintusSmit asked on
PHPWeb Development
3 Comments2 Solutions550 ViewsLast Modified:
Hi

I am working on a simple site where my student can upload files to a local hosted server.
The site runs in http://localhost/uploader.

The uploaded files reside in http://localhost/uploader/files
The problem is that when I upload the file via a form it only saves the link without the site folder as in http://localhost/files.

So the correct link to an uploaded file would be http://localhost/uploader/files/myfile.jpg
but the system save the link as http://localhost/files/myfile.jpg.


I can manually put the "uploader" folder in the saved link but want to know if there is a more elegant way to do it.

Here is the code:

if (isset($_POST['fileSubmit'])){
	$year = $_POST['year'];
	$course = $_POST['course'];
	$fileName = $_FILES['courseFile']['name'];
	$name = $_POST['name'];
	$target = UPLOADPATH.$fileName;
	//to do - use variables instead of explicit paths
	if( move_uploaded_file($_FILES['courseFile']['tmp_name'], "../files/downloads/{$_FILES['courseFile']['name']}")){
		echo "File moved to ".$target;	
		//now load xml file
		echo $name;
		echo '<br/>';
		echo $course;
		echo '<br/>';
		$xmlFile = simplexml_load_file("../files/filelist.xml");
		$newFile = $xmlFile->addChild('file');
		$newFile->addChild('title', $name);
		$newFile->addChild('year', $year);
		$newFile->addChild('course', $course);
		$newFile->addChild('link', $target);
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros