Oh, I forgot to mention one necessary change:
you should also add
$field = BOLTinit($field, $args['file']);
before
$current_filename = $_FILES[$field]['name'];
And when you think about it, you cannot save the filepath of the image in a
data var, or you will not be able to use the data var to display the image.
The directory has to be supposed a known piece of information (always the
same for this data var).
Thus, you should only put at the end:
$_POST[$field] = $new_filename;
Cheers,
Tiffany
Le samedi 23 mai 2015 14:17:02 UTC+2, Tiffany Grenier a écrit :
>
> The main difference I was thinking if between name and rawname is that
> rawname contains no extension. For example, newname would be "sth.jpg" wile
> rawnewname would be only "sth" (and then the extension would be the one of
> the uploaded file).
>
> Anyway, after a nice week of vacations and some busy day back to work, I
> have solved this problem and heer is the code changes I suggest to achieve
> what I wanted:
> Replace
> $newtype = strtolower(substr($new_filename, strrpos($new_filename, '.') +
> 1));
> by
> $dotIndex = strrpos($new_filename, '.');
> if($dotIndex === FALSE) {
> $newtype = $type;
> $new_filename = $new_filename.'.'.$type;
> }
> else $newtype = strtolower(substr($new_filename, $dotIndex + 1));
>
> and add at the end of the function the following line (in order to be able
> to save the newly created file name (with the implicit extension, and
> potentially custom location)) with savedata:
> $_POST[$field] = "$dir/$new_filename";
>
> With these changes, the following form works well on my website:
> [form]
> big pic: [file avatar]
> basic pic: [file upload]
> [submit UPLOAD]
> [command upload dir=members]
> [command upload name={id} file=avatar dir=members]
> [command savedata upload,avatar page="member.{id}"]
> [form]
>
>
>
> Also, I suggest that you replace
> function BOLTXupload($value, $field, $args='') {
> global $pageLink;
> [...]
> if (BOLTauth($pageLink, $BOLTid, 'uploads') == false) return BOLTabort(
> 'upload_fail_auth');
> by
> function BOLTXupload($value, $field, $args='') {
> global $pageLink,$BOLTid;
> if (BOLTauth($pageLink, $BOLTid, 'uploads') == false) return BOLTabort(
> 'upload_fail_auth');
> [...]
>
> because at the moment, your auth check is worth nothing since
> - $BOLTid is not declared global and is thus empty
> - what is the point in doing any processing of data if we are going to
> abort anyway?
>
>
> Cheers,
> Tiffany/Maelite
>
>
> Le mardi 19 mai 2015 18:13:45 UTC+2, Dan a écrit :
>>
>> The changes you suggested look very good. I changed the names of the vars
>> slightly to uploadImgTypes and uploadFileTypes to match with the img: and
>> file: markups. Users will have to remember to update their config files
>> from uploadTypes to the two new config settings. This will be in the next
>> release.
>>
>> As for uploading multiple files, what changes would we need to make to
>> the core to make that happen? I guess we need to specify somehow which file
>> upload goes with each which command? The command looks like it is already
>> set. Perhaps we need to specify something in the file input field, like an
>> id or name? Let me know and I can add it to the core. Or I can dig into it
>> when I find some time...
>>
>> You should already be able to rename the uploaded file putting
>> name='newname' in the upload command (rather than rawname). Does this not
>> work?
>>
>> Cheers,
>> Dan
>>
>> PS. Thanks again for all your great suggestions.
>>
>> On Mon, May 11, 2015 at 1:40 AM Tiffany Grenier <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> After my suggestions a few months ago to add svg to the allowed file
>>> types, I started thinking about making this more dynamic, and I have come
>>> with the idea of introducing the following configuration items:
>>> *uploadImagesTypes* (by default,, gif,jpg,jpeg,png,svg) and
>>> *uploadOtherTypes* (by default, pdf,txt) instead of the current
>>> *uploadTypes*, and getting rid of hardcoded file types in the code.
>>>
>>> -in commands.php, replace:
>>> $types = BOLTconfig('uploadTypes', 'gif,jpg,jpeg,png,txt,pdf,svg');
>>> by
>>> $types = BOLTconfig('uploadImagesTypes', 'gif,jpg,jpeg,png,svg');
>>> $types .= ','.BOLTconfig('uploadOtherTypes', 'pdf,txt');
>>>
>>> - in markups.php, replace
>>> MarkUp('links', 'image',
>>> '/(img|link)\:(([-_a-zA-Z0-9\/\:\.]+)\.(gif|jpg|jpeg|png|svg|pdf))/e',
>>> "BOLTMuploads('$2')"); // img:file.gif
>>> by
>>> $uploadImagesTypes = BOLTconfig('uploadImagesTypes',
>>> 'gif,jpg,jpeg,png,svg');
>>> $uploadImagesTypes = str_replace(',','|',$uploadImagesTypes);
>>> MarkUp('links', 'image', '/(img|link)\:(([-_a-zA-Z0-9\/\:\.]+)\.('.
>>> $uploadImagesTypes.'))/e', "BOLTMuploads('$2')"); // img:file.gif
>>> $uploadOtherTypes = BOLTconfig('uploadOtherTypes', 'pdf,txt');
>>> $uploadOtherTypes = str_replace(',','|',$uploadOtherTypes);
>>> MarkUp('links', 'files', '/(file|link)\:(([-_a-zA-Z0-9\/\:\.]+)\.('.$
>>> uploadOtherTypes.'))/e', "BOLTMuploads('$2')"); // file:file.pdf
>>>
>>> - in markups.php, replace
>>> if (inlist(substr($file, strrpos($file, '.') + 1),
>>> 'jpg,gif,png,jpeg,svg')) $type = 'img';
>>> by
>>> if (inlist(substr($file, strrpos($file, '.') + 1), BOLTconfig(
>>> 'uploadImagesTypes', 'gif,jpg,jpeg,png,svg'))) $type = 'img';
>>>
>>> and
>>> if (strpos('jpg,gif,png,jpeg,svg', substr(strrchr($file, "."), 1)) !==
>>> false) {
>>> by
>>> if (strpos(BOLTconfig('uploadImagesTypes', 'gif,jpg,jpeg,png,svg'),
>>> substr(strrchr($file, "."), 1)) !== false) {
>>>
>>>
>>> I would also suggest the possibility to upload more than one file at
>>> once, and to rename a file during upload while keeping its current file
>>> extension.
>>> Then I could do
>>> [file smallpic]
>>> [file bigpic]
>>> [command upload smallpic dir=members rawname={id}]
>>> [command upload bigpic dir=members]
>>> [command savedata smallpic,bigpic page=member.{id}]
>>>
>>> Any remark, idea, comment?
>>>
>>> Cheers,
>>> Tiffany
>>>
>>> --
>>> 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.