[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [6646] Property: multiuploader
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [6646] Property: multiuploader |
Date: |
Fri, 26 Nov 2010 10:13:48 +0000 |
Revision: 6646
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6646
Author: sigurdne
Date: 2010-11-26 10:13:47 +0000 (Fri, 26 Nov 2010)
Log Message:
-----------
Property: multiuploader
Modified Paths:
--------------
trunk/property/inc/class.fileuploader.inc.php
trunk/property/inc/class.uientity.inc.php
Modified: trunk/property/inc/class.fileuploader.inc.php
===================================================================
--- trunk/property/inc/class.fileuploader.inc.php 2010-11-26 09:31:24 UTC
(rev 6645)
+++ trunk/property/inc/class.fileuploader.inc.php 2010-11-26 10:13:47 UTC
(rev 6646)
@@ -53,35 +53,22 @@
$upload_target = phpgw::get_var('upload_target');
$id = phpgw::get_var('id');
- $link_data = array
- (
- 'menuaction' =>
$upload_target,
- 'id' => $id,
- 'last_loginid' =>
phpgw::get_var('last_loginid'),
- 'last_domain' =>
phpgw::get_var('last_domain'),
- 'sessionphpgwsessid' =>
phpgw::get_var('sessionphpgwsessid'),
- 'domain' =>
phpgw::get_var('domain')
- );
-
$oArgs = "{menuaction:'$upload_target',"
."id:'$id',"
."last_loginid:'".
phpgw::get_var('last_loginid')."',"
."last_domain:'" .
phpgw::get_var('last_domain')."',"
."sessionphpgwsessid:'" .
phpgw::get_var('sessionphpgwsessid')."',"
- ."domain:'" . phpgw::get_var('domain')."'}";
+ ."domain:'" . phpgw::get_var('domain')."'";
-
-
foreach ($_GET as $varname => $value)
{
if(strpos($varname, '_')===0)
{
-
$link_data[substr($varname,1,strlen($varname)-1)] = $value;
+ $oArgs .= ',' .
substr($varname,1,strlen($varname)-1) . ":'{$value}'";
}
}
+ $oArgs .= '}';
- $upload_url = $GLOBALS['phpgw']->link('/index.php',
$link_data);
-
$js_code = self::get_js($oArgs);
$title = lang('fileuploader');
@@ -117,24 +104,7 @@
</body>
</html>
HTML;
-
-
-
-
echo $html;
-
-/*
-
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
-
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/fonts/fonts-min.css');
- phpgwapi_yui::load_widget('uploader');
-
-
$GLOBALS['phpgw']->xslttpl->add_file(array('fileuploader'));
- $data = array
- (
- 'js_code' => $js_code,
- );
- $GLOBALS['phpgw']->xslttpl->set_var('phpgw',
array('fileuploader' => $data));
-*/
}
@@ -145,7 +115,6 @@
$str_base_url .= phpgw::get_var('HTTPS', 'bool',
'SERVER') ? 's' : '' ;
$str_base_url .= '://';
$str_base_url .= phpgw::get_var('HTTP_HOST', 'string',
'SERVER');
-//_debug_array($str_base_server);
$str_base_url .= $GLOBALS['phpgw']->link('/', array(),
true);
$js_code = <<<JS
@@ -242,8 +211,9 @@
*/
- function upload()
+ function upload($bofiles, $save_path = '')
{
+ $use_vfs = true;
// Check post_max_size
(http://us3.php.net/manual/en/features.file-upload.php#73762)
$POST_MAX_SIZE = ini_get('post_max_size');
$unit = strtoupper(substr($POST_MAX_SIZE, -1));
@@ -253,12 +223,16 @@
{
header("HTTP/1.1 500 Internal Server Error");
// This will trigger an uploadError event in SWFUpload
echo "POST exceeded maximum allowed size.";
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
// Settings
- // $save_path = dirname(__FILENAME__) . "/uploads/";
// The path were we will save the file (getcwd() may not be reliable and should
be tested in your environment)
- $save_path =
"{$GLOBALS['phpgw_info']['server']['temp_dir']}/";
+
+ if(!$save_path)
+ {
+ $save_path =
"{$GLOBALS['phpgw_info']['server']['temp_dir']}";
+ $use_vfs = false;
+ }
$upload_name = "Filedata";
$max_file_size_in_bytes = 2147483647;
// 2GB in bytes
$extension_whitelist = array("jpg", "gif", "png");
// Allowed file extensions
@@ -283,22 +257,22 @@
if (!isset($_FILES[$upload_name]))
{
$this->HandleError("No upload found in \$_FILES
for " . $upload_name);
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
else if (isset($_FILES[$upload_name]["error"]) &&
$_FILES[$upload_name]["error"] != 0)
{
$this->HandleError($uploadErrors[$_FILES[$upload_name]["error"]]);
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
else if (!isset($_FILES[$upload_name]["tmp_name"]) ||
address@hidden($_FILES[$upload_name]["tmp_name"]))
{
$this->HandleError("Upload failed
is_uploaded_file test.");
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
else if (!isset($_FILES[$upload_name]['name']))
{
$this->HandleError("File has no name.");
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
// Validate the file size (Warning: the largest files supported
by this code is 2GB)
@@ -306,13 +280,13 @@
if (!$file_size || $file_size > $max_file_size_in_bytes)
{
$this->HandleError("File exceeds the maximum
allowed size");
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
if ($file_size <= 0)
{
$this->HandleError("File size outside allowed
lower bound");
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
// Validate file name (for our purposes we'll just remove
invalid characters)
@@ -320,17 +294,33 @@
if (strlen($file_name) == 0 || strlen($file_name) >
$MAX_FILENAME_LENGTH)
{
$this->HandleError("Invalid file name");
+ $GLOBALS['phpgw']->common->phpgw_exit();
+ }
+
+
+ $to_file = "{$save_path}/{$file_name}";
+
+ // Validate that we won't over-write an existing file
+ if ($bofiles->vfs->file_exists(array(
+ 'string' => $to_file,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
+ {
+ $receipt['error'][]=array('msg'=>lang('This
file already exists !'));
+ $this->HandleError("File with this name already
exists");
exit(0);
}
+ $bofiles->create_document_dir($save_path);
+/*
// Validate that we won't over-write an existing file
- if (file_exists($save_path . $file_name))
+ if (file_exists("{$save_path}/{$file_name}"))
{
$this->HandleError("File with this name already
exists");
exit(0);
}
-
+*/
// Validate file extension
$path_info = pathinfo($_FILES[$upload_name]['name']);
$file_extension = $path_info["extension"];
@@ -346,7 +336,7 @@
if (!$is_valid_extension)
{
$this->HandleError("Invalid file extension");
- exit(0);
+ $GLOBALS['phpgw']->common->phpgw_exit();
}
// Validate file contents (extension and mime-type can't be
trusted)
@@ -370,13 +360,28 @@
Depending on your server OS and needs you may
need to set the Security Permissions on the file after it has
been saved.
*/
- if (address@hidden($_FILES[$upload_name]["tmp_name"],
$save_path.$file_name))
+
+ $bofiles->vfs->override_acl = 1;
+ if(!$bofiles->vfs->cp (array (
+ 'from' => $_FILES[$upload_name]["tmp_name"],
+ 'to' => "{$save_path}/{$file_name}",
+ 'relatives' => array
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
{
+ $receipt['error'][]=array('msg'=>lang('Failed
to upload file !'));
$this->HandleError("File could not be saved.");
exit(0);
}
- exit(0);
+ $bofiles->vfs->override_acl = 0;
+
+/*
+ if (address@hidden($_FILES[$upload_name]["tmp_name"],
"{$save_path}/{$file_name}"))
+ {
+ $this->HandleError("File could not be saved.");
+ exit(0);
+ }
+*/
+// exit(0);
}
/* Handles the error output. This error message will be sent to
the uploadSuccess event handler. The event handler
Modified: trunk/property/inc/class.uientity.inc.php
===================================================================
--- trunk/property/inc/class.uientity.inc.php 2010-11-26 09:31:24 UTC (rev
6645)
+++ trunk/property/inc/class.uientity.inc.php 2010-11-26 10:13:47 UTC (rev
6646)
@@ -159,8 +159,8 @@
$jasperfile = phpgw::get_var('jasperfile',
'bool');
$fileuploader = CreateObject('property.fileuploader');
- $fileuploader->upload();
+
if(!$this->acl_add && !$this->acl_edit)
{
$GLOBALS['phpgw']->common->phpgw_exit();
@@ -177,7 +177,6 @@
foreach ($_FILES as $fieldName => $file)
{
move_uploaded_file($file['tmp_name'],
"{$GLOBALS['phpgw_info']['server']['temp_dir']}/" .
strip_tags(basename($file['name'])));
- echo (" ");
}
$GLOBALS['phpgw']->common->phpgw_exit();
}
@@ -192,52 +191,7 @@
$bofiles = CreateObject('property.bofiles');
- $files = array();
- foreach ($_FILES as $fieldName => $file)
- {
- $file_name = str_replace('
','_',strip_tags(basename($file['name'])));
- if($jasperfile)
- {
- $file_name = 'jasper::' . $file_name;
- }
- $to_file =
"{$bofiles->fakebase}/{$this->category_dir}/{$loc1}/{$id}/{$file_name}";
-
- if ($bofiles->vfs->file_exists(array(
- 'string' => $to_file,
- 'relatives' =>
Array(RELATIVE_NONE)
- )))
- {
-
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
- }
- else
- {
- $files[] = array
- (
- 'from_file' =>
$file['tmp_name'],
- 'to_file' => $to_file
- );
- }
-
- unset($to_file);
- unset($file_name);
- }
-
$bofiles->create_document_dir("{$this->category_dir}/{$loc1}/{$id}");
- $bofiles->vfs->override_acl = 1;
- foreach ($files as $file)
- {
- if(!$bofiles->vfs->cp (array (
- 'from' => $file['from_file'],
- 'to' => $file['to_file'],
- 'relatives' => array
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
- {
-
$receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
- }
- echo (" ");
- }
- $bofiles->vfs->override_acl = 0;
- unset($loc1);
- unset($files);
- unset($file);
+ $fileuploader->upload($bofiles,
"{$bofiles->fakebase}/{$this->category_dir}/{$loc1}/{$id}");
}
function columns()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [6646] Property: multiuploader,
Sigurd Nes <=