Visualizzazione risultati 1 fino 4 di 4

Discussione: Aprire directory! Visualizzare più file attraverso variabili in array.

  1. #1
    Guest

    Predefinito Aprire directory! Visualizzare più file attraverso variabili in array.

    ragazzi non sapevo che scrivere come titolo e poi perdonatemi... sono le 3 di notte passate perchè non riesco a finire questo cavolo di script.

    Allora, devo aprire una directory, e poi attraverso dei valori definiti in un array, stampare a video, attraverso un template, tutte le immagini.

    Nel template il tutto viene definito una volta perchè dovrebbe automaticamente creare una lista con la formattazione ma il problema è che mi stampa solamente l'ultima immagine della cartella.

    Ecco lo script che utilizzo:
    Codice PHP:
    <?php

    define
    ('IN_ICYPHOENIX', true);
    if (!
    defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
    if (!
    defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
    include(
    IP_ROOT_PATH . 'common.' . PHP_EXT);
    include(
    IP_ROOT_PATH . 'language/lang_' . $board_config['default_lang'] . '/lang_banners.' . PHP_EXT);

    // Start session management
    $userdata = session_pagestart($user_ip);
    init_userprefs($userdata);
    // End session management

    $template->set_filenames(array('body' => 'banners_body.tpl'));

    $path_banners = './';

    $path = $_SERVER['REQUEST_URI'];

    switch(
    $_GET['size']) {
    default:
    $select_size = $lang['Select_Size'];
    message_die(GENERAL_MESSAGE, $select_size);
    break;

    case
    '120x60':
    $dir = $path_banners . 'linkaci/120x60/';
    $size_view = '120x60';
    break;

    case
    '88x31':
    $dir = $path_banners . 'linkaci/88x31/';
    $size_view = '88x31';
    }

    if (
    $_GET['size'] == '') {
    $select_size = $lang['Select_Size'];
    message_die(GENERAL_MESSAGE, $select_size);
    }

    elseif (
    $dir_handle = @opendir($dir) or die("Non riesco ad aprire $dir")) {

    while (
    false !== ($file = readdir($dir_handle))) {
    if (
    $file != "." && $file != "..") {

    $image = '<img src=' . $dir . $file . ' />';
    $size_image = filesize($dir . $file);
    $last_edit_file_time = filemtime($dir . $file);
    $bbcode_code = '[url=' . $path . '][img]' . $dir . $file . '[/img][/url]';
    $html_code = '<a href="' . $path . '" title="Making Art.org">' . $image . '</a>';
    $direct_code = $dir . $file;

    $template->assign_vars(array(
    'SIZE_VIEW' => $size_view,
    'SIZE_IMAGE' => $size_image,
    'LAST_EDIT_FILE_TIME' => date("j/m/Y h:i", $last_edit_file_time),
    'IMAGE' => $image,
    'BBCODE_CODE' => $bbcode_code,
    'HTML_CODE' => $html_code,
    'DIRECT_CODE' => $direct_code,
    )
    );
    }
    }
    }

    // Start output of page
    $page_title = $size_view;
    $meta_description = '';
    $meta_keywords = '';
    //define('SHOW_ONLINE', true);

    include(IP_ROOT_PATH . 'includes/page_header.' . PHP_EXT);

    //parse and build page
    $template->pparse('body');

    //include the phpBB footer
    include(IP_ROOT_PATH . 'includes/page_tail.' . PHP_EXT);

    ?>
    Il template (banners_body.tpl)
    Codice HTML:
    {IMG_THL}{IMG_THC}<span class="forumlink">{SIZE_VIEW}</span>{IMG_THR}<table class="forumlinenb" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td align="center">
       <table width="100%">
       <tr>
       <td align="center" width="50%">{IMAGE}</td>
       <td align="left" width="50%">
       <span class="generation">{SIZE_IMAGE} Byte<br />
       Caricato il : {LAST_EDIT_FILE_TIME}</span><br />
       </td>
       </tr>
       </table>
       <table>
       <tr align="left">
       <td width="50"><label for="{TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_HTML}"><b>HTML:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:30px;" name="{TEXTAREA_ID}" onClick="javascript:this.form.{TEXTAREA_ID}.focus();this.form.{TEXTAREA_ID}.select();" class="generation">{HTML_CODE}</textarea>
       </form>
       </td>
       </tr>
       <tr align="left">
       <td width="50"><label for="{TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_BBCODE}"><b>BBCode:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:30px;" name="{TEXTAREA_ID}" onClick="javascript:this.form.{TEXTAREA_ID}.focus();this.form.{TEXTAREA_ID}.select();" class="generation">{BBCODE_CODE}</textarea>
       </form>
       </td>
       </tr>
       <tr align="left">
       <td width="50"><label for="{TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_URL}"><b>Url:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:15px;" name="{TEXTAREA_ID}" onClick="javascript:this.form.{TEXTAREA_ID}.focus();this.form.{TEXTAREA_ID}.select();" class="generation">{DIRECT_CODE}</textarea>
       </form>
       </td>
       </tr>
       </table>
       </td>
       </tr>
    </table>{IMG_TFL}{IMG_TFC}{IMG_TFR}
    Ora ho due problemi:
    1. Riuscire a stampare, quindi generare, TUTTI i file nella directory.
    2. Devo definire TEXTAREA_ID nell'array in modo che il label prenda lo stesso ID della textarea in modo da selezionare automaticamente il codice.

    Grazie in anticipo a tutti ragazzi

  2. #2
    Guest

    Predefinito

    Prova così
    Codice PHP:
    <?php

    define
    ('IN_ICYPHOENIX', true);
    if (!
    defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
    if (!
    defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
    include(
    IP_ROOT_PATH . 'common.' . PHP_EXT);
    include(
    IP_ROOT_PATH . 'language/lang_' . $board_config['default_lang'] . '/lang_banners.' . PHP_EXT);

    // Start session management
    $userdata = session_pagestart($user_ip);
    init_userprefs($userdata);
    // End session management

    $template->set_filenames(array('body' => 'banners_body.tpl'));

    $path_banners = './';

    $path = $_SERVER['REQUEST_URI'];

    switch(
    $_GET['size']) {
    default:
    $select_size = $lang['Select_Size'];
    message_die(GENERAL_MESSAGE, $select_size);
    break;

    case
    '120x60':
    $dir = $path_banners . 'linkaci/120x60/';
    $size_view = '120x60';
    break;

    case
    '88x31':
    $dir = $path_banners . 'linkaci/88x31/';
    $size_view = '88x31';
    }

    if (
    $_GET['size'] == '') {
    $select_size = $lang['Select_Size'];
    message_die(GENERAL_MESSAGE, $select_size);
    }

    elseif (
    $dir_handle = @opendir($dir) or die("Non riesco ad aprire $dir")) {

    $T_ID=0;

    while (
    false !== ($file = readdir($dir_handle))) {
    if (
    $file != "." && $file != "..") {

    $image = '<img src="' . $dir . $file . '" />';
    $size_image = filesize($dir . $file);
    $last_edit_file_time = filemtime($dir . $file);
    $bbcode_code = '[url=' . $path . '][img]' . $dir . $file . '[/img][/url]';
    $html_code = '<a href="' . $path . '" title="Making Art.org">' . $image . '</a>';
    $direct_code = $dir . $file;

    $template->assign_block_vars('image', array(
    'SIZE_VIEW' => $size_view,
    'SIZE_IMAGE' => $size_image,
    'LAST_EDIT_FILE_TIME' => date("j/m/Y h:i", $last_edit_file_time),
    'IMAGE' => $image,
    'BBCODE_CODE' => $bbcode_code,
    'HTML_CODE' => $html_code,
    'DIRECT_CODE' => $direct_code,
    'TEXTAREA_ID' => $T_ID
    )
    );
    $T_ID++;
    }
    }
    }

    // Start output of page
    $page_title = $size_view;
    $meta_description = '';
    $meta_keywords = '';
    //define('SHOW_ONLINE', true);

    include(IP_ROOT_PATH . 'includes/page_header.' . PHP_EXT);

    //parse and build page
    $template->pparse('body');

    //include the phpBB footer
    include(IP_ROOT_PATH . 'includes/page_tail.' . PHP_EXT);

    ?>
    template
    Codice:
    {IMG_THL}{IMG_THC}
    <!-- BEGIN image -->
    <span class="forumlink">{image.SIZE_VIEW}</span>{IMG_THR}<table class="forumlinenb" width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td align="center">	
       <table width="100%">
       <tr>
       <td align="center" width="50%">{image.IMAGE}</td>
       <td align="left" width="50%">
       <span class="generation">{image.SIZE_IMAGE} Byte<br />
       Caricato il : {image.LAST_EDIT_FILE_TIME}</span><br />
       </td>
       </tr>
       </table>
       <table>
       <tr align="left">
       <td width="50"><label for="{image.TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_HTML}"><b>HTML:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:30px;" name="{image.TEXTAREA_ID}" onClick="javascript:this.form.{image.TEXTAREA_ID}.focus();this.form.{image.TEXTAREA_ID}.select();" class="generation">{image.HTML_CODE}</textarea>
       </form>
       </td>
       </tr>
       <tr align="left">
       <td width="50"><label for="{image.TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_BBCODE}"><b>BBCode:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:30px;" name="{image.TEXTAREA_ID}" onClick="javascript:this.form.{image.TEXTAREA_ID}.focus();this.form.{image.TEXTAREA_ID}.select();" class="generation">{image.BBCODE_CODE}</textarea>
       </form>
       </td>
       </tr>
       <tr align="left">
       <td width="50"><label for="{image.TEXTAREA_ID}" class="post-details" style="cursor:pointer;" title="{L_SELECT_BANNER_CODE_URL}"><b>Url:</b></label></td>
       <td width="100%">
       <form name="select_all">
       <textarea readonly="readonly" style="width:100%;height:15px;" name="{image.TEXTAREA_ID}" onClick="javascript:this.form.{image.TEXTAREA_ID}.focus();this.form.{image.TEXTAREA_ID}.select();" class="generation">{image.DIRECT_CODE}</textarea>
       </form>
       </td>
       </tr>
       </table>
       </td>
       </tr>   
    </table>
    <!-- END image -->
    {IMG_TFL}{IMG_TFC}{IMG_TFR}

  3. #3
    Guest

    Predefinito

    Ho modificato un pò il codice ma devo dire che è perfetto, funziona che una meraviglia.

    grazie mille Stoner

  4. #4
    Guest

    Predefinito

    Di nulla figurati, per così poco ;)

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •