specific folder upload

gogrin

New member
Hi is it posible to upload images to specific folders, i mean if im making albums for different people, that i could upload say:

Mike's photos to mike's folder and Maria's to the maria folder, both inside the uploads folder.

maybe also add the option to automaticly create this folder
 

eugenio

Administrator
Staff member
No at the moment it isn't.
If you are interested in implementing this feature please contact me.

Bye,

 

billthecat

Well-known member
eugenio,

is there any reason you/we couldn't do something like this (I haven't tried it yet):

Change config.php file relative URL section to this:

// relative url from the DaDaBIK root dir to the upload folder - please put slash (/) at the end
$_SESSION['username_user'] = $loggeduser;
$upload_relative_url = 'uploads/'$loggeduser'/';

//check if user upload folder exists - if not, create it
$filename = $upload_relative_url'/'$loggeduser;

if (file_exists($filename)) {
echo "";
} else {
mkdir($upload_relative_url'/'$loggeduser);
}

 

billthecat

Well-known member
There are some obvious flaws in what I've written above, so I rewrote it a little....so far this is working for me, using DaDaBIK 4.1:

// relative url from the DaDaBIK root dir to the upload folder - please put slash (/) at the end
session_start();
$loggeduser = $_SESSION['logged_user_infos_ar']['username_user'];
$upload_relative_url = 'uploads/';
$upload_relative_url .= $loggeduser."/";
//check if user upload folder exists - if not, create it
$filename = $upload_relative_url;

if (file_exists($filename)) {
echo "";
} else {
mkdir($upload_relative_url);
}

// absolute path of the upload dir - please put slash (/) at the end
// e.g. 'c:\\data\\web\\dadabik\\uploads\\' on windows systems
// e.g. '/home/my/path/dadabik/uploads/' on unix systems
// make sure the webserver can write in this folder and in the temporary upload folder used by PHP (see php.ini for details)
$upload_directory = '/home/my/path/dadabik/uploads/';
$upload_directory .= $loggeduser."/";
 

eugenio

Administrator
Staff member
Hi,
I have not tested your mod but it seems correct to me; I don't understandt echo "" though.

 

billthecat

Well-known member
I suppose a better way would be to say:

while(file_exists($filename) == false){
mkdir($upload_relative_url);
}
 

eugenio

Administrator
Staff member
Maybe it's more clear in this way:

if (file_exists($filename) === false) {
mkdir($upload_relative_url);
}

Bye,

 

DebbieS

DaDaBIK Guru
Have you tried using the same methodology outlined above but using the $table_name variable as the trigger instead of the username?

 

guppy

New member
I have a wish that i think linked to this subject.
During creation or updating of fields I don't want to upload pictures or files, but to chose between available pictures/files in 2-3 different folders on the server.

Ideally the user should browse e.g. pictures and chose one that suits him and then only the filename (e.g. mypicture.jpg) should be stored in the table field.
If not possible to browse the files on the server it could be a solution to browse local thumbs of pictures (much smaller size) and upload them, but still necessary to recover the filename to use for reports with the high definition image.

I would almost have a solution if possible to find where to change code to avoid renaming of already existing filenames (e.g. mypicture.jpg becomes mypicture_1.jpg if I upload the same file twice.

I have looked at the index.php without finding where to cancel the renaming.
 

billthecat

Well-known member
This sounds like it could get a bit complicated, depending on how you want things to work.
For instance, you're saying to browse for files in the 'pictures' directory during an insert or update process. Browse ALL pictures, or is there some record in your database of which to show the user? How secure is your pictures directory? If not at all, why not just make a link to the open directory, IE:
business_logic.php

Look for:
if ($form_type == "insert")

At the end of the 'if' statement, replace:

$form .= ">";

with:

if ($field_name_temp === 'pictures') {
$form .= "><a href=\"pictures\">Pictures</a>";
} else {
$form .= ">";
}

You could also use the same method to make a link page (link.php) that looks in the directory for files:
<?php
if ($link = opendir('/home/username/public_html/images')) {
while (false !== ($file = readdir($link))) {
if ($file != "." && $file != ".." && !is_dir($file)) {
echo "<a href=\"$file\">$file</a>\n<br>";
}
}
closedir($link);
}
?>

 

guppy

New member
Thank you for the input.
When I try the first one it doesn't change anything it brings me to the local hard disk - still the problem with filenames being incremented when uploading same file more than once.
The second code, where should I put that? I tried editing the same line as for the first one but the directory gives error - perhaps because it is not a sub directory of /dadabik.
Explanation of the setup:
I have 50 pictures on the server to use for existing and new records containing product information (>1000 products). This means that each picture will be used several times but no need to upload it more than once.
The field type is image_file.
 

billthecat

Well-known member
In the examples that I gave, you would need to make sure the field used is not an upload field, but a text field, and of course change the name to match (field_name_temp). My examples only allow you to see the available files, and then write them in the box.
Which is one of the reasons this becomes complicated...if you want it an integrated part of the form, a new field type would have to be added that could be similar to a select_single, but selecting from your images directory.

The second I gave needs to be its own page, and the first example linking to it:

if ($field_name_temp === 'pictures') {
$form .= "><a href=\"link.php\">Pictures</a>";
} else {
$form .= ">";
}


Now make a file in your dadabik directory (link.php):
<?php
if ($link = opendir('/home/username/public_html/images')) { // change the directory for your needs
while (false !== ($file = readdir($link))) {
if ($file != "." && $file != ".." && !is_dir($file)) {
echo "<a href=\"$file\">$file</a>\n<br>";
}
}
closedir($link);
}
?>

 

guppy

New member
I manage to make it work with the link.php but I had to move the picture file folder to dadabik/
Clicking 'picture' next to the field when editing brings to a page with a list of filenames, but if I click one of them it gives an error 404. So what I can do is selecting a filename and copy it - then return to the field editing and paste the value. It is not perfect as there is no preview of the picture chosen.
I'll continue working on it, I think I will find sooner or later. If not with Dadabik I'm almost sure I can do it using Joomla with the component Fabrik, but I would prefer just to use a "standalone" like Dadabik.
 

billthecat

Well-known member
You could add a javascript popup window to display the image

http://www.dynamicdrive.com/dynamicindex4/imagetooltip.htm



Post Edited (03-12-09 18:19)
 
Top