Joomla 2.5的视力模块杀死我一直在努力
大部分都有效,但是我必须使用ftp上传图片,因为上传部分不起作用?我会喜欢这方面的帮助,除了那个洞之外的事情
mod_kos.php
<?php
defined('_JEXEC') or die('ERROR: Restricted access');
$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::root().'modules/mod_kos/tmpl/css/style.css');
require_once( dirname(__FILE__).DS.'helper.php' );
//$kos = modKOSHelper::getKOS ( $params );
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
$max = ini_get('upload_max_filesize');
$module_dir = $params->get( 'dir' );
$file_type = $params->get( 'type' );
$msg = '';
require( JModuleHelper::getLayoutPath( 'mod_kos' ) );
?>
helper.php
<?php
defined('_JEXEC') or die('ERROR: Restricted access');
class modKOSHelper
{
// function getKOS
public static function getKOS ( $params )
{
if(strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
$input = new JInput;
$post = $input->getArray($_POST);
$image = $post["image"];
$name = $post["name"];
$wanted = $post["wanted"];
$pay = $post["pay"];
//image and name set, continue-->
$data =new stdClass();
$data->id = NULL;
$data->image = $image;
$data->name = $name;
$data->wanted = $wanted;
$data->pay = $pay;
$db = JFactory::getDBO();
$db->insertObject('#__my_kos', $data, id);
}
}
//end function getKOS
function fileUpload($max, $module_dir, $file_type, $msg){
//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('image', null, 'files', 'array');
if(isset($file)){
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
if($file['size'] > $max) $msg = JText::_('ONLY_FILES_UNDER').' '.$max;
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = $module_dir . DS .$filename;
//First check if the file has the right extension, we need jpg only
if ($file['type'] == $file_type || $file_type == '*'); {
if ( JFile::upload($src, $dest) ); {
//Redirect to a page of your choice
$msg = JText::_('FILE_SAVE_AS').''.$dest;
} else {
//Redirect and throw an error message
$msg = JText::_('ERROR_IN_UPLOAD');
}
} else {
//Redirect and notify user file is not right extension
$msg = JText::_('FILE_TYPE_INVALID');
}
$msg = "<script>alert('". $msg ."');</script>";
}
return $msg;
}
// end of file upload
// function getdb
public static function getdb($params)
{
// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__my_kos');
// sets up a database query for later execution
$db->setQuery($query);
// fetch result as an object list
$result = $db->loadObjectList();
echo '<div id="container">';
foreach ($result as $row){
echo '<div style="background-image: url(modules/mod_kos/images/wanted.png); height: 256px; width: 200px; border: 1px solid black;"><img src="modules/mod_kos/images/' . $row->image . ' ">';
echo '</div>';
echo '<div id="name">';
echo "<t1>Description: </t1>";
echo "<t2>$row->name</t2>";
echo '</div>';
echo '<div id="wanted">';
echo "<t1>Bounty: </t1>";
echo "<t2>$row->wanted</t2>";
echo '</div>';
echo '<div id="pay">';
echo "<t1>Payer: </t1>";
echo "<t2>$row->pay</t2>";
echo '</div>';
echo "<br>";
}
echo '</div>';
}
// end function getDB
}
?>
如default.php
<?php
// no direct access
defined( '_JEXEC' ) or die( 'ERROR: Restricted access' );
$kos = modKOSHelper::getdb ( $params );
if(isset($_POST['cleartext']))
{
$sent = bounty($response);
if($sent) $b_sent = true;
}
?>
<!--build the form------------>
<form name="bounty" id="bounty" action="<?php echo JURI::current(); ?>" method="POST" onSubmit="if(image.value=='') {alert('Choose a file!');return false;}">
<fieldset>
<legend><hl>Add New Bounty</hl></legend>
<p><sf1>PICTURE:<br><input type="file" name="image" id="image" /></sf1></p>
<p><sf2>DESC:<br><input type="text" name="name" id="name" value="" /></sf2></p>
<p><sf3>BOUNTY:<br><input type="text" name="wanted" id="wanted" value="" /></sf3></p>
<p><sf4>PAYER:<br><input type="text" name="pay" id="pay" value="" /></sf4></p>
<p><input id="submit" name="submit" type="submit" class="button" value="Submit Bounty" /></p>
<p><input type="submit" id="clear" name="clear" class="button" value="clear" onClick="cleartext(); return false;"></p>
</fieldset>
</form>
<!--END BUILD THE FORM-->
<script type="text/javascript">
function cleartext()
{
alert(document.getElementById('name').value);
document.getElementById('image').value = '';
document.getElementById('name').value = '';
document.getElementById('wanted').value = '';
document.getElementById('pay').value = '';
alert(document.getElementById('name').value);
}
var bClear = <?= $b_sent? 'true':'false' ?>;
if (bClear) cleartext();
</script>