用于扩展JFormField的文件

时间:2012-09-23 20:34:50

标签: php forms

我将此代码放在一个名为iconbasic的文件中,该文件应该运行我的个人资料图片上传器,但它无效。任何人都知道为什么?

我是新手,但是,组件fron-end中的agentform文件夹有一个edit.php文件,里面有这一行:

<?php echo $this->form->getInput('icon'); ?>

然后在models文件夹中,我们有agent.xml文件,它基本上使用以下行指向iconbasic.php:

    <field name="icon" type="iconbasic" label="COM_IPROPERTY_IMAGE" readonly="true" folder="agents" />

然后在组件的管理员文件中,我在名为fields的子文件夹内的models文件夹中有一个名为iconbasic.php的文件。 在前端,该网站允许我上传文件,然后我发现它们存储在正确的目录中,但它们没有在网站上显示。我试图找出原因,并真的很感激一些帮助。没有编码经验,今天我或多或少地使用记事本++ :)

这是iconbasic.php文件:

<?php
/**
 * @version 2.0 2012-01-20
 * @package Joomla
 * @subpackage Intellectual Property
 * @copyright (C) 2012 the Thinkery
 * @license GNU/GPL see LICENSE.php
 */

defined('JPATH_BASE') or die;

jimport('joomla.html.html');
jimport('joomla.form.formfield');

class JFormFieldIconBasic extends JFormField
{
protected $type = 'Iconbasic';

protected function getInput()
{
    $user       = JFactory::getUser();
    $document   = JFactory::getDocument();
    $folder     = $this->element['folder']; // agents or companies
    $id         = JRequest::getInt('id');
    $settings   = ipropertyAdmin::config();
    $database   = JFactory::getDBO();

    switch ($folder){
        case 'agents':
            $width = $settings->agent_photo_width;
            $table = '#__iproperty_agents';
        break;
        case 'companies':
            $width = $settings->company_photo_width;
            $table = '#__iproperty_companies';
        break;
        default:
            $width = $settings->agent_photo_width;
            $table = '#__iproperty_agents';
        break;
    }

    $sql = "SELECT icon FROM ".$table." WHERE id = ".$id;
    $database->setQuery($sql);
    $icon = $database->loadResult();

    if (!$icon) $icon = 'nopic.png';


    $document->addScript( "http://bp.yahooapis.com/2.4.21/browserplus-min.js" );
    $document->addScript( "https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" );
    $document->addScript( JURI::root()."components/com_iproperty/assets/js/plupload/js/plupload.full.js" );

    $script = 
"jQuery.noConflict();
jQuery(document).ready(function($) {
var uploader = new plupload.Uploader({
    runtimes : 'html5,flash,silverlight,browserplus',
    browse_button : 'pickfiles',
    container : 'container',
    max_file_size : '2mb',
    unique_names : true,
    multipart: true,
    urlstream_upload: true,
    url : '".JURI::root()."index.php?option=com_iproperty&task=ajax.ajaxIconUpload&format=raw&".JUtility::getToken()."=1&target=".$folder."&id=".$id."',
    flash_swf_url : '".JURI::root()."components/com_iproperty/assets/js/plupload/js/plupload.flash.swf',
    silverlight_xap_url : '".JURI::root()."components/com_iproperty/assets/js/plupload/js/plupload.silverlight.xap',
    filters : [
        {title : 'Image files', extensions : 'jpg,gif,png'}
        //{title : '".JText::_('COM_IPROPERTY_IMAGE_TYPES')."', extensions : '".JText::_('COM_IPROPERTY_IMAGE_EXTENSIONS')."'}
    ],
    resize : {width : ".$width.", height : ".$width.", quality : 90} // we use the same value for width/height so it scales proportionally
});

$('#uploadfiles').click(function(e) {
    uploader.start();
    e.preventDefault();
});

uploader.init();

uploader.bind('FilesAdded', function(up, files) {
    $.each(files, function(i, file) {
        $('#filelist').append(
            '<div id=\"' + file.id + '\">' +
            file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
        '</div>');
    });

    uploader.start(); // auto start when file added

    up.refresh(); // Reposition Flash/Silverlight
});

uploader.bind('UploadProgress', function(up, file) {
    $('#' + file.id + \" b\").html(file.percent + \"%\");
});

uploader.bind('Error', function(up, err) {
console.log(err);
    $('#filelist').append(\"<div>Error: \" + err.code +
        \", Message: \" + err.message +
        (err.file ? \", File: \" + err.file.name : \"\") +
        \"</div>\"
    );
    up.refresh(); // Reposition Flash/Silverlight
});

uploader.bind('FileUploaded', function(up, file, info) {
    var finfo = jQuery.parseJSON(info.response);
    if (finfo[0].status){ // successful image upload
        var path = '".JURI::root()."media/com_iproperty/".$folder."/'+finfo[0].result;
        $('#ip_photo_holder').attr('src', path);
    }
});
});"."\n";   

    $document->addScriptDeclaration($script);
    // Build image select js and load the view
    $img_path   = JURI::root(true).'/media/com_iproperty/'.$folder.'/';     
    ?>
    <div style="padding: 4px;" id="container">
        <div id="filelist"></div><br />
        <a id="pickfiles" href="javascript:void(0);">[Select files]</a>
        <a id="uploadfiles" href="javascript:void(0);">[Upload files]</a>
    </div>
    <div><img id="ip_photo_holder" src="<?php echo JURI::root(); ?>/media/com_iproperty/<?php echo $folder.'/'.$icon; ?>"></div>
    <?php
}
}

1 个答案:

答案 0 :(得分:0)

这是manage.php文件中的一行错误的SQL位