I am trying to upload files using php to directory that is not in the same directory that the upload script is, here is the structure of dir's:
var>www>html>
foo>index.php //this ones where upload is done
bar> //this is where I want to upload it
the index.php file's form element:
<form enctype="multipart/form-data" method="POST" action="index.php">
<fieldset style='width:33%;'>
<legend>UPLOAD PROJECT FILES</legend>
<select name="dirList" id="dirList" onChange="getSubDir(this.value)" required>
<option value="">SELECT PROJECT</option>
<?php
$path = "../";
$scan = scandir($path);
foreach($scan as $result){
if($result === '.' or $result === '..') continue;
if(is_dir($path . '/' . $result)){
echo "<option value='../$result'>$result</option>";
}
}
?>
</select>
<select name="subDirList" id="subDirList">
<option value="">SELECT PATH</option>
</select>
<input type="file" name="filePath"/>
<input type="submit" name = "upload" value="UPLOAD"/>
</fieldset>
</form>
so the idea here is to get the list of folders from first combobox which will get me the list of subdirectories in the second combobox.
and then the php function at the head of index.php for uploading the file:
if(isset($_POST['upload'])){
$upload_path = $_POST['subDirList'];
if($upload_path == ''){
$upload_path = $_POST['dirList'];
}
$upload_path = getcwd().'/'.$upload_path;
$upload_path = $upload_path.'/'.basename($_FILES['filePath']['name']);
if(move_uploaded_file($_FILES["filePath"]["tmp_name"], $upload_path)){
echo "success";
} else {
echo print_r($_FILES);
echo 'fail';
}
}
the error log:
[Wed Sep 23 14:10:46.841250 2015] [:error] [pid 4028] [client 78.167.168.253:52438] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpEB1a3s' to '/var/www/html/eShop/Capture.PNG' in /var/www/html/ftp/index.php on line 16, referer: http://xxx.xx.xx.xx/ftp/index.php