Thanks with your help on the upload command. I posted my final draft below.
If you care to check and make sure it works on your test case I'd
appreciate it. Pretty straightforward, though. Looks good!
Cheers,
Dan
function BOLTXupload($value, $field, $args='') {
global $pageLink;
if (BOLTauth($pageLink, $BOLTid, 'uploads') == false) return
BOLTabort('upload_fail_auth');
$types = BOLTconfig('uploadImgTypes', 'gif,jpg,jpeg,png,svg');
$types .= ','.BOLTconfig('uploadFileTypes', 'pdf,txt');
$a_types = BOLTinit($types, $args['types']);
$size = BOLTconfig('uploadSize', 100000);
$a_size = BOLTinit($size, $args['size']);
$case = BOLTconfig('uploadCase', false);
$a_case = BOLTinit($case, $args['case']);
$dir = BOLTinit('files', $args['dir']);
$field = BOLTinit($field, $args['file']);
$current_filename = $_FILES[$field]['name'];
if (trim($current_filename) === '') return
BOLTabort("upload_no_file::$field");
if (strpos($current_filename, '.') === false) return
BOLTabort('upload_no_ext'); // checks file name
$type = strtolower(substr($current_filename, strrpos($current_filename,
'.') + 1));
if (! inlist($type, $types) || ! inlist ($type, $a_types)) return
BOLTabort("upload_fail_type::$type");
$new_filename = BOLTinit($current_filename, $args['name']);
if ($a_case !== 'true') $new_filename = strtolower($new_filename);
$dotIndex = strrpos($new_filename, '.');
if($dotIndex === FALSE) {
$newtype = $type;
$new_filename = $new_filename.'.'.$type;
}
else $newtype = strtolower(substr($new_filename, $dotIndex + 1));
if (inlist($newtype, 'jpg,jpeg') && ! inlist($type, 'jpg,jpeg')) return
BOLTabort("upload_error"); // checks new name
elseif ($newtype != $type) return BOLTabort("upload_error");
if (BOLTconfig('uploadsStrict', 'true') == 'true') {
if (BOLTfilter($current_filename, 'uploads') == '' ||
BOLTfilter($new_filename, 'uploads') == '') return
BOLTabort("upload_error"); // checks new name
}
if ($dir != 'files') {
$check = BOLTfilter($dir, '-_a-z0-9');
if ($check == '') return BOLTabort('upload_fail_dir');
$dir = "files/$check";
}
BOLTfixdir($dir, false);
if ($_FILES[$field]['error'] != UPLOAD_ERR_OK) return
BOLTabort("upload_error::$new_filename");
if ($_FILES[$field]['size'] > $size || $_FILES[$field]['size'] > $a_size )
return BOLTabort("upload_fail_size::$new_filename");
$success = move_uploaded_file($_FILES[$field]['tmp_name'],
"$dir/$new_filename");
if ($success) {
chmod("$dir/$new_filename", 0644);
BOLTmessage("upload_success::$new_filename", $args);
}
else BOLTmessage("upload_fail::$new_filename", $args);
clearstatcache();
}
On Mon, May 25, 2015 at 2:29 AM Tiffany Grenier <[email protected]>
wrote:
> It also appears that upload_no_file is a message I created. It goes as
> follow:
> upload_no_file: File is missing for upload field "$1".
>
>
>
> Le dimanche 24 mai 2015 13:33:41 UTC+2, Tiffany Grenier a écrit :
>
>> Sure, here is the code I am running:
>>
>> function BOLTXupload($value, $field, $args='') {
>> global $pageLink,$BOLTid;
>> if (BOLTauth($pageLink, $BOLTid, 'uploads') == false) return
>> BOLTabort('upload_fail_auth');
>> $types = BOLTconfig('uploadImgTypes', 'gif,jpg,jpeg,png,svg');
>> $types .= ','.BOLTconfig('uploadFileTypes', 'txt,pdf');
>> $a_types = BOLTinit($types, $args['types']);
>> $size = BOLTconfig('uploadSize', 100000);
>> $a_size = BOLTinit($size, $args['size']);
>> $case = BOLTconfig('uploadCase', false);
>> $a_case = BOLTinit($case, $args['case']);
>> $dir = BOLTinit('files', $args['dir']);
>> $field = BOLTinit($field, $args['file']);
>> $current_filename = $_FILES[$field]['name'];
>> if (trim($current_filename) === '') return BOLTabort(
>> "upload_no_file::$field");
>> // checks file name
>> if (strpos($current_filename, '.') === false) return BOLTabort(
>> "upload_no_ext");
>> $type = strtolower(substr($current_filename, strrpos(
>> $current_filename, '.') + 1));
>> if (! inlist($type, $types) || ! inlist ($type, $a_types)) return
>> BOLTabort("upload_fail_type::$type");
>> $new_filename = BOLTinit($current_filename, $args['name']);
>> if ($a_case !== 'true') $new_filename = strtolower($new_filename);
>> $dotIndex = strrpos($new_filename, '.');
>> if($dotIndex === FALSE) {
>> $newtype = $type;
>> $new_filename = $new_filename.'.'.$type;
>> }
>> else $newtype = strtolower(substr($new_filename, $dotIndex + 1));
>> // checks new name
>> if (inlist($newtype, 'jpg,jpeg') && ! inlist($type, 'jpg,jpeg'))
>> return BOLTabort("upload_error::$new_filename"); //jpg and jpeg are the
>> same
>> elseif ($newtype != $type) return BOLTabort(
>> "upload_error::$new_filename");
>> if (BOLTconfig('uploadsStrict', 'true') == 'true') {
>> if (BOLTfilter($current_filename, 'uploads') == '' || BOLTfilter(
>> $new_filename, 'uploads') == '') return BOLTabort(
>> "upload_error::$new_filename");
>> }
>> if ($dir != 'files') {
>> $check = BOLTfilter($dir, '-_a-z0-9');
>> if ($check == '') return BOLTabort("upload_fail_dir::$dir");
>> $dir = "files/$check";
>> }
>> BOLTfixdir($dir, false);
>> if ($_FILES[$field]['error'] != UPLOAD_ERR_OK) return BOLTabort(
>> "upload_error::$new_filename");
>> if ($_FILES[$field]['size'] > $size || $_FILES[$field]['size'] >
>> $a_size ) return BOLTabort("upload_fail_size::$new_filename");
>> $success = move_uploaded_file($_FILES[$field]['tmp_name'],
>> "$dir/$new_filename");
>> if ($success) {
>> chmod("$dir/$new_filename", 0644);
>> BOLTmessage("upload_success::$new_filename", $args);
>> }
>> else BOLTmessage("upload_fail::$new_filename", $args);
>> clearstatcache();
>> $_POST[$field] = $new_filename;
>> }
>>
>> Cheers,
>> Tiffany
>>
>>
>> Le dimanche 24 mai 2015 11:48:14 UTC+2, Dan a écrit :
>>
>> Tiffany, could you post the full upload function with all these changes
>> together--that would be easier than me piecing together the improvements
>> you have made. Thanks for these suggestions. Will be good to have this in
>> BoltWire 5!
>>
>> Cheers,
>> Dan
>>
>> On Sat, May 23, 2015 at 11:10 PM Tiffany Grenier <grenier...@gmail.
>>
>> ...
>
> --
> You received this message because you are subscribed to the Google Groups
> "BoltWire" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/boltwire.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"BoltWire" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/boltwire.
For more options, visit https://groups.google.com/d/optout.