嗨,大家好,我正在自定義一個joomla的房地產組件1.5該組件功能的一部分是網站管理員可以上傳PDF以配合描述個人房地產項目的方式與上傳項目圖片的腳本完全相同。事情是雖然表單上傳了腳本,但瀏覽網站的用戶實際上看不到它。他們點擊鏈接並得到403禁止的錯誤。 Web服務器可以看到該文件,但沒有人有權查看該文件。我檢查了包含pdf文件的文件夾的權限,他們沒事(755)。我已經檢查了上傳的PDF文件的權限,有時它們在Dreamweaver中顯示爲完全沒有權限,有時顯示爲644或600.我確實想過要將chmod命令合併到某處,但我正在工作與joomla和許多代碼是joomla特定的,這使得很難清楚地看到發生了什麼。你們能幫我解決問題嗎?代碼如下:php表單上傳並沒有爲上傳的文件分配任何權限
非常感謝
<?php
/*------------------------------------------------------------------------
# com_properties
# ------------------------------------------------------------------------
# author Fabio Esteban Uzeltinger
# copyright Copyright (C) 2011 com-property.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: www.com-property.com
# Technical Support: www.com-property.com/forum-v4
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
$TableName = 'pdfs';
$component_name = 'properties';
JHTML::_('behavior.tooltip');
?>
<script language="javascript" type="text/javascript">
<!--
function submitbutton(pressbutton) {
var form = document.adminForm;
/*var type = form.type.value;*/
if (pressbutton == 'cancel') {
submitform(pressbutton);
return;
}
if (document.getElementById('name').value == "") {
alert("Item must have a Title");
}
else if(document.getElementById('parent').value == 0){
alert("Please select a Product");
}
else {
submitform(pressbutton);
}
}
//-->
function jSelectProperty(id, title, object) {
document.getElementById(object + '_id').value = id;
document.getElementById(object + '_name').value = title;
document.getElementById('parent').value = id;
document.getElementById('sbox-window').close();
}
</script>
<?php
require_once(JPATH_COMPONENT.DS.'helpers'.DS.'menu_left.php');
?>
<table class="admintable" width="100%">
<tr>
<td align="left" width="200px" valign="top">
<?php echo MenuLeft::ShowMenuLeft();?>
</td>
<td align="left" valign="top" class="td_form">
<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
<div class="col100">
<fieldset class="adminform2">
<legend><?php echo JText::_('Add Pdf'); ?></legend>
<table>
<tr>
<td width="50%" >
<table>
<tr>
<td class="paramlist_key" width="40%">
<span class="editlinktip">
<label id="urlparamsid-lbl" for="urlparamsid" class="hasTip">
<?php echo JText::_('Parent Product'); ?>
</label>
</span>
</td>
<td class="paramlist_value">
<?php
require_once(JPATH_COMPONENT.DS.'elements'.DS.'property.php');
$node=null;
$control_name='';
echo JElementProperty::fetchElement('parent', $this->datos->parent, &$node, $control_name);
?>
<input type="hidden" name="parent" id="parent" value="<?php echo $this->datos->parent;?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="name">
<?php echo JText::_('Nombre'); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="name" id="name" style="width:270px;" size="60" maxlength="250" value="<?php echo $this->datos->name;?>" />
</td>
</tr>
<tr>
<td class="key">
<label for="name">
<?php echo JText::_('Published'); ?>:
</label>
</td>
<td>
<?php $chequeado0 = $this->datos->published ? JText::_('') : JText::_('checked="checked"');?>
<?php $chequeado1 = $this->datos->published ? JText::_('checked="checked"') : JText::_('');?>
<?php if($this->datos->published==''){
$chequeado1=JText::_('checked="checked"');$chequeado0=JText::_('');}?>
<input name="published" id="published1" value="1" <?php echo $chequeado1;?> type="radio">
<label for="published1"><?php echo JText::_('Yes'); ?></label>
<input name="published" id="published0" value="0" <?php echo $chequeado0;?> type="radio">
<label for="published0"><?php echo JText::_('No'); ?></label>
</td>
</tr>
<tr>
<td class="key">
<label for="name">
<?php echo JText::_('Ordering'); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="ordering" id="ordring" style="width:72px;" size="20" maxlength="255" value="<?php echo $this->datos->ordering; ?>" />
</td>
</tr>
<tr>
<td class="key">
<?php echo JText::_('Archivo'); ?>
</td>
<td>
<?php
if($this->datos->archivo){ ?>
<a href="<?php echo JURI::root().'images/properties/pdfs/'.$this->datos->parent.'/'.$this->datos->archivo; ?>" target="_blank">
<?php echo $this->datos->archivo;
}?>
</a>
</td>
</tr>
<tr>
<td align="center">
<input type="file" size="20" name="archivo" value=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table class="admintable" width="100%">
<tr>
<td>
<?php $editor = &JFactory::getEditor();
echo $editor->display('text', $this->datos->text, '100%', '400', '60', '20');
?>
</td>
</tr>
</table>
</fieldset>
</div>
<div class="clr"></div>
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="table" value="<?php echo $TableName; ?>" />
<input type="hidden" name="id" value="<?php echo $this->datos->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="view" value="<?php echo $TableName; ?>" />
<input type="hidden" name="controller" value="<?php echo $TableName; ?>" />
</form>
</td>
</tr>
</table>
表格處理腳本
<?php
/*------------------------------------------------------------------------
# com_properties
# ------------------------------------------------------------------------
# author Fabio Esteban Uzeltinger
# copyright Copyright (C) 2011 com-property.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: www.com-property.com
# Technical Support: www.com-property.com/forum-v4
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
class PropertiesControllerPdfs extends PropertiesController
{
function __construct()
{
parent::__construct();
$this->registerTask('add' , 'edit');
$this->registerTask('apply', 'save');
$this->registerTask('save2new', 'save');
$this->registerTask('unpublish', 'publish');
}
function display()
{
parent::display();
}
function edit()
{
JRequest::setVar('view', 'pdfs');
JRequest::setVar('layout', 'form');
parent::display();
}
function save()
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$this->TableName='pdfs';
global $mainframe;
$component_name = 'properties';
$option = JRequest::getVar('option');
$model = $this->getModel('pdfs');
$post = JRequest::get('post');
$db =& JFactory::getDBO();
require_once(JPATH_SITE.DS.'configuration.php');
$datos = new JConfig();
$basedatos = $datos->db;
$dbprefix = $datos->dbprefix;
$query = "SHOW TABLE STATUS FROM `".$basedatos."` LIKE '".$dbprefix.$component_name."_".$this->TableName."';";
$db->setQuery($query);
$nextAutoIndex = $db->loadObject();
if(JRequest::getVar('id')){ $id_archivo = JRequest::getVar('id');
}else{$id_archivo = $nextAutoIndex->Auto_increment;}
if($_FILES['archivo']['name']) {
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
$path = JPATH_SITE.DS.'images'.DS.'properties'.DS.'pdfs'.DS.$post['parent'].DS;
if(!JFolder::exists($path))
{
JFolder::create($path,0755);
}
$ext = JFile::getExt($_FILES['archivo']['name']);
$filename = $post['name'].'.'.$ext;
$move_to=$path.$filename;
if(JFolder::move($_FILES['archivo']['tmp_name'], $move_to))
{
chmod ($filename,0755);
$post['archivo'] = $filename;
}
}
$text = JRequest::getVar('text', '', 'post', 'string', JREQUEST_ALLOWRAW);
$post['text'] = $text;
$datenow =& JFactory::getDate();
$post['date'] = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
if ($model->store($post)) {
$msg = JText::_('Saved').' ('.$post['name'].') ';
switch (JRequest::getCmd('task'))
{
case 'apply':
$this->setRedirect('index.php?option=com_properties&view=pdfs&layout=form&task=edit&cid[]='.$id_archivo);
break;
case 'save':
$this->setRedirect('index.php?option=com_properties&view=pdfs');
break;
case 'save2new':
$this->setRedirect(JRoute::_('index.php?option=com_properties&view=pdfs&layout=form&task=edit', false));
$msg.=JText::_('You can add new Product.');
break;
}
} else {
$msg = JText::_('Error Saving Greeting');
$msg .= 'err'.$this->Err;
}
$this->setMessage(JText::_($msg));
}
function remove()
{
//echo 'remove';
$model = $this->getModel('pdfs');
if(!$model->delete()) {
$msg = JText::_('Error: One or More Greetings Could not be Deleted');
} else {
$msg = JText::_('Deleted') ;
}
$this->setRedirect('index.php?option=com_properties&view=pdfs',$msg);
}
function cancel()
{
$this->TableName = JRequest::getCmd('table');
$msg = JText::_('Operation Cancelled');
//$this->setRedirect('index.php?option=com_properties&table='.$this->TableName, $msg);
parent::display();
}
}
百勝餐飲,意大利麪條時間。 – moonwave99
不完全有幫助的傢伙!是的,我正在使用非英語發言者創建的代碼。儘管如此,它仍然是非常好的代碼。 – Cervantes01
[意大利麪代碼](http://en.wikipedia.org/wiki/Spaghetti_code) – moonwave99