Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
ckupload.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Upload image from CKeditor
8  *
9  * @author Anakeen
10  * @version $Id: fckupload.php,v 1.3 2008/03/10 10:45:52 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/modcard.php");
18 /**
19  * Upload image from CKeditor
20  * @param Action &$action current action
21  * @global $_FILES['upload'] Http var : file to store
22  */
23 function ckupload(Action & $action)
24 {
25  $errors = [];
26 
27  $usage = new ActionUsage($action);
28  $usage->setStrictMode(false);
29 
30  $usage->verify();
31 
32  $dbaccess = $action->dbaccess;
33  global $_FILES;
34 
35  $doc = createDoc($dbaccess, "IMAGE");
36  try {
37  $filename = insert_file($doc, "upload", true);
38  } catch (\Exception $e) {
39  $errors []= $e->getMessage();
40  }
41 
42  if (count($errors) <= 0) {
43  if ($filename != "") {
44  $doc->setValue("img_file", $filename);
45  if (($err = $doc->store()) !== '') {
46  $errors [] = $err;
47  } else {
48  $action->lay->set("docid", $doc->getPropertyValue("id"));
49  $action->lay->set("title", $doc->getTitle());
50  }
51  } else {
52  $errors [] = _("Unable to store the file");
53  }
54  }
55 
56  if (count($errors) <= 0) {
57  $data = [
58  'uploaded' => 1,
59  'fileName' => $filename,
60  'url' => sprintf('?sole=A&app=FDL&action=EXPORTFILE&cache=no&docid=%s&attrid=img_file&index=-1', $doc->getPropertyValue('id'))
61  ];
62  } else {
63  $data = [
64  'uploaded' => 0,
65  'error' => [
66  'message' => implode("\n", $errors)
67  ]
68  ];
69  }
70  $action->lay->set("DATA", json_encode($data, JSON_PRETTY_PRINT));
71 }
global $action
$filename
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
Verify arguments for action function.
$dbaccess
Definition: checkVault.php:17
insert_file(Doc &$doc, $attrid, $strict=false)
Definition: modcard.php:365
if($file) if($subject==""&&$file) if($subject=="") $err
ckupload(Action &$action)
Definition: ckupload.php:23
$usage
$data
← centre documentaire © anakeen