dwmccay
Založený: 16.07.2008
Príspevky: 2
Zaslal: 2008-07-16 22:26
Návrat hore
Odpovedať s citátom
|
I have a DB field that contains the name of an image. In the edit and add views I would like to give the user a list of image names (or somehow pop up the images themselves) and when the user picks the image the field gets updated with the image name. A bonus would be to show the selected image beside the field if possible. I don't care if this uses a drop down, list box, or popup. The images are currently on my web server but could be stored in the DB if necessary (if not necessary it would be better if they could stay where they are). The names could be placed in a table as well (of course).
|
ajh
Založený: 17.12.2003
Príspevky: 236
Zaslal: 2008-07-21 12:01
Návrat hore
Odpovedať s citátom
|
I think that you could get somewhere close to this. If you have a table with the image names in, you could use this to drive your 'values' option on the field to select the names (not sure that you could display the images as well).
For the List and Display views, you could use options variability (
http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.options-variability.html
) on an 'sql' clause that could build an HTML image tag to display the image. Something like:
| Kód: |
...['sql|VL'] => 'CONCAT("<img src=\"",imagename,"\">)'
|
Where "imagename" is the field in the table with the imagename
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2008-07-28 22:38
Návrat hore
Odpovedať s citátom
|
Sounds similar to what I just figured out how to do... with the help of some previous user (Kally) here.
| Kód: |
$opts['fdd']['image'] = array(
'name' => 'Photo',
'select' => 'D',
'maxlen' => 125,
'sort' => true
);
$opts['fdd']['image']['values']= array('-- Select an Image --');
$maindir = '../pets/images/' ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php" , "secret.php") ;
while($fn = readdir($mydir))
{ if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
if ($fn != '.' && $fn != '..')
{
if(!ereg("^tn", $fn))
{
$narray[$i]=$fn;
$i++;
}
}
}
sort($narray);
for($i=0; $i<sizeof($narray); $i++)
{
array_push($opts['fdd']['image']['values'],$narray[$i]);
}
closedir($mydir);
|
|
dwmccay
Založený: 16.07.2008
Príspevky: 2
Zaslal: 2008-08-14 20:02
Návrat hore
Odpovedať s citátom
|
| v13 Napísal: |
Sounds similar to what I just figured out how to do... with the help of some previous user (Kally) here.
| Kód: |
$opts['fdd']['image'] = array(
'name' => 'Photo',
'select' => 'D',
'maxlen' => 125,
'sort' => true
);
$opts['fdd']['image']['values']= array('-- Select an Image --');
$maindir = '../pets/images/' ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php" , "secret.php") ;
while($fn = readdir($mydir))
{ if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
if ($fn != '.' && $fn != '..')
{
if(!ereg("^tn", $fn))
{
$narray[$i]=$fn;
$i++;
}
}
}
sort($narray);
for($i=0; $i<sizeof($narray); $i++)
{
array_push($opts['fdd']['image']['values'],$narray[$i]);
}
closedir($mydir);
|
|
Thanks! That eliminated the need for a table to hold the image names. Now I can just drop an image into the directory and all is well. I did have to make one slight mod. I added:
right before the while. The first time I tried it I got
Undefined variable: i
. Perhaps you had initialized $i further back in your code. Other than that it's working.
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2008-08-14 20:44
Návrat hore
Odpovedať s citátom
|
SWEET! :-)
|
guppy
Založený: 17.03.2009
Príspevky: 9
Zaslal: 2009-03-24 03:58
Návrat hore
Odpovedať s citátom
|
Thanks a lot, I was looking for something like that.
Did you manage also viewing images in the dropdown?
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2009-03-24 04:30
Návrat hore
Odpovedať s citátom
|
I haven't looked into that at all... not sure what would be the best way to go about it. If anyone has done it I'd love to know what they did, it's a nice feature.
|
guppy
Založený: 17.03.2009
Príspevky: 9
Zaslal: 2009-03-24 18:31
Návrat hore
Odpovedať s citátom
|
I have no clue yet as how to view images, but there is certainly a way.
For the moment I'm trying to change the dropdown content depending on the value of another field (two possibilities), but it doesn't work using this type of code:
| Kód: |
| if($opts['fdd']['type'] == "Red") {$maindir='/path/images/redchoice/'; } else { $maindir='/path/images/bluechoice/'; } |
It doesn't give errors but always takes the 'else' option, so it is probably the wrong way to point to the value of the 'type' field.
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2009-03-24 19:25
Návrat hore
Odpovedať s citátom
|
Just a quick guess but what if you changed the word "type" to the word "value" ....?
|
guppy
Založený: 17.03.2009
Príspevky: 9
Zaslal: 2009-03-24 21:28
Návrat hore
Odpovedať s citátom
|
Well it will not work as the field I refer to is named 'type'. But I have thought of adding ['value'] after ['type'], but this is not working either - I will check the manual for other ways of proceeding.
Ideally I would like to use ajaxfilemanager but I can't make it work from 'inside' phpMyEdit.
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2009-03-24 21:44
Návrat hore
Odpovedať s citátom
|
Have you tried using one = instead of two?
|
guppy
Založený: 17.03.2009
Príspevky: 9
Zaslal: 2009-03-24 22:28
Návrat hore
Odpovedať s citátom
|
Still no error message with only one "=" but now only the first choice is selected.
I realize that the dropdown is also in the table view - this means it is difficult to imagine having two options/folders.
|
v13
Založený: 28.07.2008
Príspevky: 9
Zaslal: 2009-03-24 23:15
Návrat hore
Odpovedať s citátom
|
Hmmm... can you paste all the code for the fields etc here?
|
guppy
Založený: 17.03.2009
Príspevky: 9
Zaslal: 2009-03-26 00:10
Návrat hore
Odpovedať s citátom
|
I have found a not perfect way to enable viewing images in the dropdown directory.
I add a line to display the 'help' for the picture field:
| Kód: |
| $opts['fdd']['picture']['help'] = '<a href="http://path/thumbs.php?about=picture" target="_blank">?</a>'; |
The thumbs.php should contain something like this:
| Kód: |
<?php
$path = "./images/";
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle))) {
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
echo "<input type=CHECKBOX name=$file>";
echo "<img src=images/$file height=100 width=100 alt='$file'><br />";
}
closedir($dir_handle);
?> |
It works ok and a check box is available for each picture. But I don't know how to get the checked image filename (or img src= etc. etc.) back to fill the field value. As preview is possible I no longer absolutely need two choices (red...blue) but all pictures can be in one directory.
The thumbs.php launches by clicking the questionmark in the third column of the Edit/Add view.
|
|
Odoslať novú tému
Odpovedať na tému
|