QuintusSmit
asked on
Full url path for uploaded file - PHP
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:
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);
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER