[ Index ] |
PHP Cross Reference of Textpattern 4.0.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 _______________________________________ 4 ________| Textpattern |________ 5 \ | Mod File Upload | / 6 \ | Michael Manfre (http://manfre.net) | / 7 / |_______________________________________| \ 8 /___________) (___________\ 9 10 Textpattern Copyright 2004 by Dean Allen. All rights reserved. 11 Use of this software denotes acceptance of the Textpattern license agreement 12 13 "Mod File Upload" Copyright 2004 by Michael Manfre. All rights reserved. 14 Use of this mod denotes acceptance of the Textpattern license agreement 15 16 $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/include/txp_file.php $ 17 $LastChangedRevision: 3069 $ 18 19 */ 20 21 if (!defined('txpinterface')) die('txpinterface is undefined.'); 22 23 $levels = array( 24 1 => gTxt('private'), 25 0 => gTxt('public') 26 ); 27 28 global $file_statuses; 29 $file_statuses = array( 30 2 => gTxt('hidden'), 31 3 => gTxt('pending'), 32 4 => gTxt('live'), 33 ); 34 35 if ($event == 'file') { 36 require_privs('file'); 37 38 if(!$step or !in_array($step, array('file_change_max_size','file_change_pageby','file_db_add','file_multi_edit','file_edit','file_insert','file_list','file_replace','file_save','file_reset_count','file_create'))){ 39 file_list(); 40 } else $step(); 41 } 42 43 // ------------------------------------------------------------- 44 45 function file_list($message = '') 46 { 47 global $txpcfg, $extensions, $file_base_path, $file_statuses, $file_list_pageby; 48 49 pagetop(gTxt('file'), $message); 50 51 extract($txpcfg); 52 53 extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); 54 55 if (!is_dir($file_base_path) or !is_writeable($file_base_path)) 56 { 57 echo graf( 58 gTxt('file_dir_not_writeable', array('{filedir}' => $file_base_path)) 59 , ' id="warning"'); 60 } 61 62 else 63 { 64 $existing_files = get_filenames(); 65 66 if (count($existing_files) > 0) 67 { 68 echo form( 69 eInput('file'). 70 sInput('file_create'). 71 72 graf(gTxt('existing_file').sp.selectInput('filename', $existing_files, '', 1).sp. 73 fInput('submit', '', gTxt('Create'), 'smallerbox')) 74 75 , 'text-align: center;'); 76 } 77 78 echo file_upload_form(gTxt('upload_file'), 'upload', 'file_insert'); 79 } 80 81 $dir = ($dir == 'desc') ? 'desc' : 'asc'; 82 83 switch ($sort) 84 { 85 case 'id': 86 $sort_sql = 'id '.$dir; 87 break; 88 89 case 'description': 90 $sort_sql = 'description '.$dir.', filename desc'; 91 break; 92 93 case 'category': 94 $sort_sql = 'category '.$dir.', filename desc'; 95 break; 96 97 case 'downloads': 98 $sort_sql = 'downloads '.$dir.', filename desc'; 99 break; 100 101 default: 102 $sort = 'filename'; 103 $sort_sql = 'filename '.$dir; 104 break; 105 } 106 107 $switch_dir = ($dir == 'desc') ? 'asc' : 'desc'; 108 109 $criteria = 1; 110 111 if ($search_method and $crit) 112 { 113 $crit_escaped = doSlash($crit); 114 115 $critsql = array( 116 'id' => "ID in ('" .join("','", do_list($crit_escaped)). "')", 117 'filename' => "filename like '%$crit_escaped%'", 118 'description' => "description like '%$crit_escaped%'", 119 'category' => "category like '%$crit_escaped%'" 120 ); 121 122 if (array_key_exists($search_method, $critsql)) 123 { 124 $criteria = $critsql[$search_method]; 125 $limit = 500; 126 } 127 128 else 129 { 130 $search_method = ''; 131 $crit = ''; 132 } 133 } 134 135 else 136 { 137 $search_method = ''; 138 $crit = ''; 139 } 140 141 $total = safe_count('txp_file', "$criteria"); 142 143 if ($total < 1) 144 { 145 if ($criteria != 1) 146 { 147 echo n.file_search_form($crit, $search_method). 148 n.graf(gTxt('no_results_found'), ' class="indicator"'); 149 } 150 151 else 152 { 153 echo n.graf(gTxt('no_files_recorded'), ' class="indicator"'); 154 } 155 156 return; 157 } 158 159 $limit = max($file_list_pageby, 15); 160 161 list($page, $offset, $numPages) = pager($total, $limit, $page); 162 163 echo file_search_form($crit, $search_method); 164 165 $rs = safe_rows_start('*', 'txp_file', "$criteria order by $sort_sql limit $offset, $limit"); 166 167 if ($rs) 168 { 169 echo '<form name="longform" method="post" action="index.php" onsubmit="return verify(\''.gTxt('are_you_sure').'\')">'. 170 171 startTable('list'). 172 173 tr( 174 column_head('ID', 'id', 'file', true, $switch_dir, $crit, $search_method, ('id' == $sort) ? $dir : ''). 175 hCell(). 176 column_head('file_name', 'filename', 'file', true, $switch_dir, $crit, $search_method, ('filename' == $sort) ? $dir : ''). 177 column_head('description', 'description', 'file', true, $switch_dir, $crit, $search_method, ('description' == $sort) ? $dir : ''). 178 column_head('file_category', 'category', 'file', true, $switch_dir, $crit, $search_method, ('category' == $sort) ? $dir : ''). 179 // column_head('permissions', 'permissions', 'file', true, $switch_dir, $crit, $search_method). 180 hCell(gTxt('tags')). 181 hCell(gTxt('status')). 182 hCell(gTxt('condition')). 183 column_head('downloads', 'downloads', 'file', true, $switch_dir, $crit, $search_method, ('downloads' == $sort) ? $dir : ''). 184 hCell() 185 ); 186 187 while ($a = nextRow($rs)) 188 { 189 extract($a); 190 191 $edit_url = '?event=file'.a.'step=file_edit'.a.'id='.$id.a.'sort='.$sort. 192 a.'dir='.$dir.a.'page='.$page.a.'search_method='.$search_method.a.'crit='.$crit; 193 194 $file_exists = file_exists(build_file_path($file_base_path, $filename)); 195 196 $download_link = ($file_exists) ? '<li>'.make_download_link($id, '', $filename).'</li>' : ''; 197 198 $category = ($category) ? '<span title="'.htmlspecialchars(fetch_category_title($category, 'file')).'">'.$category.'</span>' : ''; 199 200 $tag_url = '?event=tag'.a.'tag_name=file_download_link'.a.'id='.$id.a.'description='.urlencode($description). 201 a.'filename='.urlencode($filename); 202 203 $condition = '<span class="'; 204 $condition .= ($file_exists) ? 'ok' : 'not-ok'; 205 $condition .= '">'; 206 $condition .= ($file_exists) ? gTxt('file_status_ok') : gTxt('file_status_missing'); 207 $condition .= '</span>'; 208 209 echo tr( 210 211 n.td($id). 212 213 td( 214 '<ul>'. 215 '<li>'.href(gTxt('edit'), $edit_url).'</li>'. 216 $download_link. 217 '</ul>' 218 , 65). 219 220 td( 221 href(htmlspecialchars($filename), $edit_url) 222 , 125). 223 224 td(htmlspecialchars($description), 150). 225 td($category, 90). 226 227 /* 228 td( 229 ($permissions == '1') ? gTxt('private') : gTxt('public') 230 ,80). 231 */ 232 233 td( 234 n.'<ul>'. 235 n.t.'<li><a target="_blank" href="'.$tag_url.a.'type=textile" onclick="popWin(this.href, 400, 250); return false;">Textile</a></li>'. 236 n.t.'<li><a target="_blank" href="'.$tag_url.a.'type=textpattern" onclick="popWin(this.href, 400, 250); return false;">Textpattern</a></li>'. 237 n.t.'<li><a target="_blank" href="'.$tag_url.a.'type=xhtml" onclick="popWin(this.href, 400, 250); return false;">XHTML</a></li>'. 238 n.'</ul>' 239 , 75). 240 241 td($file_statuses[$status], 45). 242 243 td($condition, 45). 244 245 td( 246 ($downloads == '0' ? gTxt('none') : $downloads) 247 , 25). 248 249 td( 250 fInput('checkbox', 'selected[]', $id) 251 , 10) 252 ); 253 } 254 255 echo tr( 256 tda( 257 select_buttons(). 258 file_multiedit_form($page, $sort, $dir, $crit, $search_method) 259 ,' colspan="10" style="text-align: right; border: none;"') 260 ). 261 262 endTable(). 263 '</form>'. 264 265 nav_form('file', $page, $numPages, $sort, $dir, $crit, $search_method). 266 267 pageby_form('file', $file_list_pageby); 268 } 269 } 270 271 // ------------------------------------------------------------- 272 273 function file_search_form($crit, $method) 274 { 275 $methods = array( 276 'id' => gTxt('ID'), 277 'filename' => gTxt('file_name'), 278 'description' => gTxt('description'), 279 'category' => gTxt('file_category') 280 ); 281 282 return search_form('file', 'file_list', $crit, $methods, $method, 'filename'); 283 } 284 285 // ------------------------------------------------------------- 286 287 function file_multiedit_form($page, $sort, $dir, $crit, $search_method) 288 { 289 $methods = array( 290 'changecategory' => gTxt('changecategory'), 291 'delete' => gTxt('delete'), 292 ); 293 294 return event_multiedit_form('file', $methods, $page, $sort, $dir, $crit, $search_method); 295 } 296 297 // ------------------------------------------------------------- 298 299 function file_multi_edit() 300 { 301 $selected = ps('selected'); 302 303 if (!$selected or !is_array($selected)) 304 { 305 return file_list(); 306 } 307 308 $selected = array_map('assert_int', $selected); 309 $method = ps('edit_method'); 310 $changed = array(); 311 312 if ($method == 'delete') 313 { 314 return file_delete($selected); 315 } 316 317 if ($method == 'changecategory') 318 { 319 foreach ($selected as $id) 320 { 321 if (safe_update('txp_file', "category = '".doSlash(ps('category'))."'", "id = $id")) 322 { 323 $changed[] = $id; 324 } 325 } 326 } 327 328 if ($changed) 329 { 330 update_lastmod(); 331 332 return file_list(gTxt('file_updated', array('{name}' => join(', ', $changed)))); 333 } 334 335 return file_list(); 336 } 337 338 // ------------------------------------------------------------- 339 340 function file_edit($message = '', $id = '') 341 { 342 global $txpcfg, $file_base_path, $levels, $file_statuses; 343 344 pagetop(gTxt('file'), $message); 345 346 extract(gpsa(array('name', 'category', 'permissions', 'description', 'sort', 'dir', 'page', 'crit', 'search_method', 'publish_now'))); 347 348 if (!$id) 349 { 350 $id = gps('id'); 351 } 352 $id = assert_int($id); 353 354 $categories = getTree('root', 'file'); 355 356 $rs = safe_row('*, unix_timestamp(created) as created, unix_timestamp(modified) as modified', 'txp_file', "id = $id"); 357 358 if ($rs) 359 { 360 extract($rs); 361 362 if ($permissions=='') $permissions='-1'; 363 364 $file_exists = file_exists(build_file_path($file_base_path,$filename)); 365 $replace = ($file_exists) ? tr(td(file_upload_form(gTxt('replace_file'),'upload','file_replace',$id))) : ''; 366 367 $existing_files = get_filenames(); 368 369 $condition = '<span class="'; 370 $condition .= ($file_exists) ? 'ok' : 'not-ok'; 371 $condition .= '">'; 372 $condition .= ($file_exists)?gTxt('file_status_ok'):gTxt('file_status_missing'); 373 $condition .= '</span>'; 374 375 $downloadlink = ($file_exists)?make_download_link($id, htmlspecialchars($filename),$filename):htmlspecialchars($filename); 376 377 $created = 378 n.graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now').'<label for="publish_now">'.gTxt('set_to_now').'</label>'). 379 380 n.graf(gTxt('or_publish_at').sp.popHelp('timestamp')). 381 382 n.graf(gtxt('date').sp. 383 tsi('year', '%Y', $rs['created']).' / '. 384 tsi('month', '%m', $rs['created']).' / '. 385 tsi('day', '%d', $rs['created']) 386 ). 387 388 n.graf(gTxt('time').sp. 389 tsi('hour', '%H', $rs['created']).' : '. 390 tsi('minute', '%M', $rs['created']).' : '. 391 tsi('second', '%S', $rs['created']) 392 ); 393 394 $form = ''; 395 396 if ($file_exists) { 397 $form = tr( 398 td( 399 form( 400 graf(gTxt('file_category').br.treeSelectInput('category', 401 $categories,$category)) . 402 // graf(gTxt('permissions').br.selectInput('perms',$levels,$permissions)). 403 graf(gTxt('description').br.text_area('description','100','400',$description)) . 404 fieldset(radio_list('status', $file_statuses, $status, 4), gTxt('status'), 'file-status'). 405 fieldset($created, gTxt('timestamp'), 'file-created'). 406 graf(fInput('submit','',gTxt('save'))) . 407 408 eInput('file') . 409 sInput('file_save'). 410 411 hInput('filename', $filename). 412 hInput('id', $id) . 413 414 hInput('sort', $sort). 415 hInput('dir', $dir). 416 hInput('page', $page). 417 hInput('crit', $crit). 418 hInput('search_method', $search_method) 419 ) 420 ) 421 ); 422 } else { 423 424 $form = tr( 425 tda( 426 hed(gTxt('file_relink'),3). 427 file_upload_form(gTxt('upload_file'),'upload','file_replace',$id). 428 form( 429 graf(gTxt('existing_file').' '. 430 selectInput('filename',$existing_files,"",1). 431 fInput('submit','',gTxt('Save'),'smallerbox'). 432 433 eInput('file'). 434 sInput('file_save'). 435 436 hInput('id',$id). 437 hInput('category',$category). 438 hInput('perms',($permissions=='-1') ? '' : $permissions). 439 hInput('description',$description). 440 hInput('status',$status). 441 442 hInput('sort', $sort). 443 hInput('dir', $dir). 444 hInput('page', $page). 445 hInput('crit', $crit). 446 hInput('search_method', $search_method) 447 448 ) 449 ), 450 ' colspan="4" style="border:0"' 451 ) 452 ); 453 } 454 echo startTable('list'), 455 tr( 456 td( 457 graf(gTxt('file_status').br.$condition) . 458 graf(gTxt('file_name').br.$downloadlink) . 459 graf(gTxt('file_download_count').br.$downloads) 460 ) 461 ), 462 $form, 463 $replace, 464 endTable(); 465 } 466 } 467 468 // ------------------------------------------------------------- 469 function file_db_add($filename,$category,$permissions,$description,$size) 470 { 471 $rs = safe_insert("txp_file", 472 "filename = '$filename', 473 category = '$category', 474 permissions = '$permissions', 475 description = '$description', 476 size = '$size', 477 created = now(), 478 modified = now() 479 "); 480 481 if ($rs) { 482 $GLOBALS['ID'] = mysql_insert_id( ); 483 return $GLOBALS['ID']; 484 } 485 486 return false; 487 } 488 489 // ------------------------------------------------------------- 490 function file_create() 491 { 492 global $txpcfg,$extensions,$txp_user,$file_base_path; 493 extract($txpcfg); 494 extract(doSlash(gpsa(array('filename','category','permissions','description')))); 495 496 $size = filesize(build_file_path($file_base_path,$filename)); 497 $id = file_db_add($filename,$category,$permissions,$description, $size); 498 499 if($id === false){ 500 file_list(gTxt('file_upload_failed').' (db_add)'); 501 } else { 502 $newpath = build_file_path($file_base_path,trim($filename)); 503 504 if (is_file($newpath)) { 505 file_set_perm($newpath); 506 file_list(gTxt('linked_to_file').' '.$filename); 507 } else { 508 file_list(gTxt('file_not_found').' '.$filename); 509 } 510 } 511 } 512 513 // ------------------------------------------------------------- 514 function file_insert() 515 { 516 global $txpcfg,$extensions,$txp_user,$file_base_path,$file_max_upload_size; 517 extract($txpcfg); 518 extract(doSlash(gpsa(array('category','permissions','description')))); 519 520 $name = file_get_uploaded_name(); 521 $file = file_get_uploaded(); 522 523 if ($file === false) { 524 // could not get uploaded file 525 file_list(gTxt('file_upload_failed') ." $name - ".upload_get_errormsg($_FILES['thefile']['error'])); 526 return; 527 } 528 529 $size = filesize($file); 530 if ($file_max_upload_size < $size) { 531 unlink($file); 532 file_list(gTxt('file_upload_failed') ." $name - ".upload_get_errormsg(UPLOAD_ERR_FORM_SIZE)); 533 return; 534 } 535 536 // Remove control characters and " * \ : < > ? / | 537 // Remove duplicate dots and any leading or trailing dots/spaces 538 $newname = preg_replace('/[\x00-\x1f\x22\x2a\x2f\x3a\x3c\x3e\x3f\x5c\x7c\x7f]+/', '', $name); 539 $newname = preg_replace('/[.]{2,}/', '.', trim($newname, '. ')); 540 541 $newpath = build_file_path($file_base_path, $newname); 542 543 if (!is_file($newname)) { 544 545 $id = file_db_add($newname,$category,$permissions,$description,$size); 546 547 if(!$id){ 548 file_list(gTxt('file_upload_failed').' (db_add)'); 549 } else { 550 551 $id = assert_int($id); 552 553 if(!shift_uploaded_file($file, $newpath)) { 554 safe_delete("txp_file","id = $id"); 555 safe_alter("txp_file", "auto_increment=$id"); 556 if ( isset( $GLOBALS['ID'])) unset( $GLOBALS['ID']); 557 file_list($newpath.' '.gTxt('upload_dir_perms')); 558 // clean up file 559 } else { 560 file_set_perm($newpath); 561 562 $message = gTxt('file_uploaded', array('{name}' => htmlspecialchars($newname))); 563 564 file_edit($message, $id); 565 } 566 } 567 } 568 569 else 570 { 571 $message = gTxt('file_already_exists', array('{name}' => $newname)); 572 573 file_list($message); 574 } 575 } 576 577 // ------------------------------------------------------------- 578 function file_replace() 579 { 580 global $txpcfg,$extensions,$txp_user,$file_base_path; 581 extract($txpcfg); 582 $id = assert_int(gps('id')); 583 584 $rs = safe_row('filename','txp_file',"id = $id"); 585 586 if (!$rs) { 587 file_list(messenger(gTxt('invalid_id'),$id,'')); 588 return; 589 } 590 591 extract($rs); 592 593 $file = file_get_uploaded(); 594 $name = file_get_uploaded_name(); 595 596 if ($file === false) { 597 // could not get uploaded file 598 file_list(gTxt('file_upload_failed') ." $name ".upload_get_errormsg($_FILES['thefile']['error'])); 599 return; 600 } 601 602 if (!$filename) { 603 file_list(gTxt('invalid_filename')); 604 } else { 605 $newpath = build_file_path($file_base_path,$filename); 606 607 if (is_file($newpath)) { 608 rename($newpath,$newpath.'.tmp'); 609 } 610 611 if(!shift_uploaded_file($file, $newpath)) { 612 safe_delete("txp_file","id = $id"); 613 614 file_list($newpath.sp.gTxt('upload_dir_perms')); 615 // rename tmp back 616 rename($newpath.'.tmp',$newpath); 617 618 // remove tmp upload 619 unlink($file); 620 } else { 621 file_set_perm($newpath); 622 if ($size = filesize($newpath)) 623 safe_update('txp_file', 'size = '.$size.', modified = now()', 'id = '.$id); 624 625 $message = gTxt('file_uploaded', array('{name}' => htmlspecialchars($name))); 626 627 file_edit($message, $id); 628 // clean up old 629 if (is_file($newpath.'.tmp')) 630 unlink($newpath.'.tmp'); 631 } 632 } 633 } 634 635 636 // ------------------------------------------------------------- 637 function file_reset_count() 638 { 639 extract(doSlash(gpsa(array('id','filename','category','description')))); 640 641 if ($id) { 642 $id = assert_int($id); 643 if (safe_update('txp_file','downloads = 0',"id = $id")) { 644 file_edit(gTxt('reset_file_count_success'),$id); 645 } 646 } else { 647 file_list(gTxt('reset_file_count_failure')); 648 } 649 } 650 651 // ------------------------------------------------------------- 652 653 function file_save() 654 { 655 global $file_base_path; 656 657 extract(doSlash(gpsa(array('id', 'filename', 'category', 'description', 'status', 'publish_now', 'year', 'month', 'day', 'hour', 'minute', 'second')))); 658 659 $id = assert_int($id); 660 661 $permissions = gps('perms'); 662 if (is_array($permissions)) { 663 asort($permissions); 664 $permissions = implode(",",$permissions); 665 } 666 667 $perms = doSlash($permissions); 668 669 $old_filename = fetch('filename','txp_file','id',$id); 670 671 if ($old_filename != false && strcmp($old_filename, $filename) != 0) 672 { 673 $old_path = build_file_path($file_base_path,$old_filename); 674 $new_path = build_file_path($file_base_path,$filename); 675 676 if (file_exists($old_path) && shift_uploaded_file($old_path, $new_path) === false) 677 { 678 $message = gTxt('file_cannot_rename', array('{name}' => $filename)); 679 680 return file_list($message); 681 } 682 683 else 684 { 685 file_set_perm($new_path); 686 } 687 } 688 689 $created_ts = @safe_strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second); 690 if ($publish_now) 691 $created = 'now()'; 692 elseif ($created_ts > 0) 693 $created = "from_unixtime('".$created_ts."')"; 694 else 695 $created = ''; 696 697 $size = filesize(build_file_path($file_base_path,$filename)); 698 $rs = safe_update('txp_file', " 699 filename = '$filename', 700 category = '$category', 701 permissions = '$perms', 702 description = '$description', 703 status = '$status', 704 size = '$size', 705 modified = now()" 706 .($created ? ", created = $created" : '') 707 , "id = $id"); 708 709 if (!$rs) 710 { 711 // update failed, rollback name 712 if (shift_uploaded_file($new_path, $old_path) === false) 713 { 714 $message = gTxt('file_unsynchronized', array('{name}' => $filename)); 715 716 return file_list($message); 717 } 718 719 else 720 { 721 $message = gTxt('file_not_updated', array('{name}' => $filename)); 722 723 return file_list($message); 724 } 725 } 726 727 $message = gTxt('file_updated', array('{name}' => $filename)); 728 729 file_list($message); 730 } 731 732 // ------------------------------------------------------------- 733 734 function file_delete($ids = array()) 735 { 736 global $file_base_path; 737 738 $ids = $ids ? array_map('assert_int', $ids) : array(assert_int(ps('id'))); 739 $fail = array(); 740 741 $rs = safe_rows_start('id, filename', 'txp_file', 'id IN ('.join(',', $ids).')'); 742 743 if ($rs) 744 { 745 while ($a = nextRow($rs)) 746 { 747 extract($a); 748 749 $filepath = build_file_path($file_base_path, $filename); 750 751 $rsd = safe_delete('txp_file', "id = $id"); 752 $ul = false; 753 754 if ($rsd && is_file($filepath)) 755 { 756 $ul = unlink($filepath); 757 } 758 759 if (!$rsd or !$ul) 760 { 761 $fail[] = $id; 762 } 763 } 764 765 766 if ($fail) 767 { 768 file_list(messenger(gTxt('file_delete_failed'), join(', ', $fail), '')); 769 } 770 else 771 { 772 file_list(gTxt('file_deleted', array('{name}' => join(', ', $ids)))); 773 } 774 } 775 else 776 { 777 file_list(messenger(gTxt('file_not_found'), join(', ', $ids), '')); 778 } 779 } 780 781 // ------------------------------------------------------------- 782 function file_get_uploaded_name() 783 { 784 return $_FILES['thefile']['name']; 785 } 786 787 // ------------------------------------------------------------- 788 function file_get_uploaded() 789 { 790 return get_uploaded_file($_FILES['thefile']['tmp_name']); 791 } 792 793 // ------------------------------------------------------------- 794 function file_set_perm($file) 795 { 796 return @chmod($file,0644); 797 } 798 799 // ------------------------------------------------------------- 800 function file_upload_form($label,$pophelp,$step,$id='') 801 { 802 global $file_max_upload_size; 803 804 if (!$file_max_upload_size || intval($file_max_upload_size)==0) $file_max_upload_size = 2*(1024*1024); 805 806 $max_file_size = (intval($file_max_upload_size) == 0) ? '': intval($file_max_upload_size); 807 808 return upload_form($label, $pophelp, $step, 'file', $id, $max_file_size); 809 } 810 811 // ------------------------------------------------------------- 812 function file_change_pageby() 813 { 814 event_change_pageby('file'); 815 file_list(); 816 } 817 818 // ------------------------------------------------------------- 819 function file_change_max_size() 820 { 821 // DEPRECATED function; removed old code 822 file_list(); 823 } 824 825 // ------------------------------------------------------------- 826 827 function make_download_link($id, $label = '', $filename = '') 828 { 829 $label = ($label) ? $label : gTxt('download'); 830 $url = filedownloadurl($id, $filename); 831 return '<a href="'.$url.'">'.$label.'</a>'; 832 } 833 834 // ------------------------------------------------------------- 835 function get_filenames() 836 { 837 global $file_base_path; 838 839 $dirlist = array(); 840 841 if (!is_dir($file_base_path)) 842 return $dirlist; 843 844 if (chdir($file_base_path)) { 845 if (function_exists('glob')) 846 $g_array = glob("*.*"); 847 else { 848 $dh = opendir($file_base_path); 849 $g_array = array(); 850 while (false !== ($filename = readdir($dh))) { 851 $g_array[] = $filename; 852 } 853 closedir($dh); 854 855 } 856 857 if ($g_array) { 858 foreach ($g_array as $filename) { 859 if (is_file($filename)) { 860 $dirlist[$filename] = $filename; 861 } 862 } 863 } 864 } 865 866 $files = array(); 867 $rs = safe_rows("filename", "txp_file", "1=1"); 868 869 if ($rs) { 870 foreach ($rs as $a) { 871 $files[$a['filename']] = $a['filename']; 872 } 873 } 874 875 return array_diff($dirlist,$files); 876 } 877 878 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu May 21 23:03:01 2009 | Cross-referenced by PHPXref 0.7 |