hi, I am building an application in webix that is going to allow users to upload document files, so I have a javascript and a PHP script,
Javascript for uploader
var uploader = {
view:"uploader",
//id:"upload",
label:"Select file to upload",
upload:"docs/upload.php",
accept:"application/pdf",
icon:"upload",
datatype:"json",
on:{
// additionally send path
onAfterFileAdd:function(upload){$$("docTree").add({ value:upload.file.name, docurl:upload.file.name});
$$("pdf").parsel(upload.file);
},
}
Javascript for my tree
var docTree ={
view:"tree",
editable:true,
editor:"text",
css:"doc_tree",
id:"docTree",
width:300,
select:true,
//data:recordsData,
editaction: 'dblclick',
drag:true,
url: "data/files.php",
datatype: "json",
type:"lineTree",
filterMode:{
showSubItems:true,
level:5
},
};
php server side
<?php
ini_set('max_execution_time',120);
$destinatioin = realpath("/opt/lampp/htdocs/site2/files/");
if(isset($_FILES['upload'])){
$file = $_FILES['upload'];
$filename = $destinatioin."/".preg_replace("|[\\\\\\/]|","",$file["name"]);
$sname = md5($file["name"]);
//cheak that file name is vaild
if($filename !== ""){
if(file_exists($filename))unlink($filename);
move_uploaded_file($file["tmp_name"], $filename);
$res = array("status" => "server", "sname" => $sname);
echo '{ "status": "server", "sname":"$sname"}';
}else{
$res =array("status" => "error");
}
echo json_encode($res);
}
?>
Q1 - I am using Linux how can one add a real path for folders in the root
Q2 - Files are not been uploaded, I want to upload files to my files folder how do i manage to do that, files are not moving to the uploads folder