Commit | Line | Data |
---|---|---|
e586807d H |
1 | <?php |
2 | /* This program is free software. It comes without any warranty, to | |
3 | * the extent permitted by applicable law. You can redistribute it | |
4 | * and/or modify it under the terms of the Do What The Fuck You Want | |
5 | * To Public License, Version 2, as published by Sam Hocevar. See | |
6 | * http://sam.zoy.org/wtfpl/COPYING for more details. */ | |
7 | ||
8 | function upload_data_file() { | |
9 | ||
10 | global $db,$error,$node; | |
11 | $node_id=$node['node_id']; | |
12 | $node_template=$_POST['node_template']; | |
13 | require(SYSTEM_ROOT.'/inc/filez.inc'); | |
14 | $suffix = array_pop(explode('.', basename($_FILES['data_file']['name']))); | |
15 | if (!is_dir(FILE_DIR.$_SESSION['user_id'])) { | |
16 | mkdir(FILE_DIR.$_SESSION['user_id']); | |
17 | } | |
18 | ||
19 | if ($suffix=='zip' && $_POST['unzip']) { | |
20 | mkdir(TMP."/".$_FILES['data_file']['name']); | |
21 | $cmd="unzip ".$_FILES['data_file']['tmp_name']." -d ".TMP."/".$_FILES['data_file']['name']; | |
22 | shell_exec($cmd); | |
23 | $handle=opendir(TMP."/".$_FILES['data_file']['name']); | |
24 | ||
25 | while (($file = readdir($handle))!==false) { | |
26 | if ($file!="." && $file!="..") { | |
27 | $node_params['node_name']=$file; | |
28 | $node_params['node_creator']=$_SESSION['user_id']; | |
29 | if ($_POST['gallery']) $node_params['template_id']="1041658"; | |
30 | else $node_params['template_id']=12; | |
31 | $node_params['node_parent']=$node['node_id']; | |
32 | ||
33 | $node_params['node_content']=$file; | |
34 | $datanode_id=nodes::addNode($node_params); | |
35 | $file_suffix = array_pop(explode('.', basename($file))); | |
36 | copy(TMP."/".$_FILES['data_file']['name']."/".$file,FILE_DIR.$_SESSION['user_id'].'/'.$datanode_id.".$file_suffix"); | |
37 | symlink(FILE_DIR.$_SESSION['user_id'].'/'.$datanode_id.".$file_suffix",SYSTEM_ROOT.'/files/'.$datanode_id); | |
38 | if ($_POST['gallery']) { | |
39 | $image=TMP."/".$_FILES['data_file']['name']."/".$file; | |
40 | $image_name=$file; | |
41 | $width=NODE_IMAGE_WIDTH; | |
42 | ||
43 | if (stristr($image_name,".jpg") || stristr($image_name,".jpeg") ){ | |
44 | $cmd=UTILZ_DIR."/jpegtopnm $image |".UTILZ_DIR."/pnmscale -width=$width | ".UTILZ_DIR."ppmquant 256 |".UTILZ_DIR."ppmtogif >".SYSTEM_ROOT."images/nodes/".substr($datanode_id,0,1)."/".substr($datanode_id,1,1)."/".$datanode_id.".gif"; | |
45 | } | |
46 | elseif (stristr($image_name,".gif")) { | |
47 | $cmd=UTILZ_DIR."/gifsicle --resize ".$width."x_ $image > ".SYSTEM_ROOT."images/nodes/".substr($datanode_id,0,1)."/".substr($datanode_id,1,1)."/".$datanode_id.".gif"; | |
48 | } | |
49 | if ($cmd) { | |
50 | shell_exec($cmd); | |
51 | } | |
52 | ||
53 | echo $cmd; | |
54 | } | |
55 | ||
56 | } | |
57 | } | |
58 | closedir($handle); | |
59 | die(); | |
60 | } | |
61 | ||
62 | else { | |
63 | copy($_FILES['data_file']['tmp_name'],FILE_DIR.$_SESSION['user_id'].'/'.$node['node_id'].".$suffix"); | |
64 | symlink(FILE_DIR.$_SESSION['user_id'].'/'.$node['node_id'].".$suffix",SYSTEM_ROOT.'/files/'.$node['node_id']); | |
65 | } | |
66 | ||
67 | ||
68 | } | |
69 | ||
70 | ?> |