php表单上传不会为上传的文件分配任何权限

时间:2012-11-08 18:07:18

标签: php file-upload joomla1.5 file-permissions permission-denied

大家好我在joomla中自定义一个房地产组件1.5该组件功能的一部分是网站管理员可以上传一个pdf,与单个房地产项目的描述一起,与脚本完全相同上传项目的图片有效。虽然表单上传了脚本,但浏览网站的人实际上看不到它。他们点击链接并获得403禁止错误。 Web服务器可以查看该文件,但没有人有权查看该文件。我已经检查了包含pdf的文件夹的权限,它们很好(755)。我已经检查了上传的pdf的权限,有时它们在Dreamweaver中显示为没有权限,有时它们显示为644或600.我确实想到尝试将chmod命令合并到某处,但我正在工作与joomla和很多代码是joomla具体,这使得很难清楚地看到发生了什么。你能帮助我,告诉我哪里出错了。代码如下:

非常感谢

 <?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();
    }   



}

1 个答案:

答案 0 :(得分:0)

更改您尝试更改文件权限的行(在类PropertiesControllerPdfs中):

chmod ($filename,0755);

包括完整路径以及文件名,i,e:

chmod ($path.$filename,0755);