Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File upload Joomla 3.3 MVC文件/pdf在自定义组件后端上传_File Upload_Joomla3.3 - Fatal编程技术网

File upload Joomla 3.3 MVC文件/pdf在自定义组件后端上传

File upload Joomla 3.3 MVC文件/pdf在自定义组件后端上传,file-upload,joomla3.3,File Upload,Joomla3.3,我想在编辑模式下从后端的自定义组件上载pdf。 国家现在是,, 1.-pdf上传正确,但数据库中未写入文件名, 2.-或者文件名写在数据库中,但JFactory::getApplication()->input看不到pdf 我发现是用enctype=“multipart/form data”做的。 在案例1中,-enctype=“multipart/form data”在中,并上载pdf 案例2。-pdf文件名写入数据库。 你知道什么?当然,我两者都需要 这里有这么多代码,这是Joomla下的一

我想在编辑模式下从后端的自定义组件上载pdf。 国家现在是,, 1.-pdf上传正确,但数据库中未写入文件名, 2.-或者文件名写在数据库中,但JFactory::getApplication()->input看不到pdf

我发现是用enctype=“multipart/form data”做的。 在案例1中,-enctype=“multipart/form data”在中,并上载pdf 案例2。-pdf文件名写入数据库。 你知道什么?当然,我两者都需要

这里有这么多代码,这是Joomla下的一个具有MVC结构的小组件com_作业!3.3:

这里只有部分文件administrator/components/com_job/views/tmpl/edit.php 使用enctype=“多部分/表单数据”

错误在哪里?我试图将enctype=“multipart/form data”放入job.xml(models)中的表单中,但没有成功

我找到了一个临时解决方案,在控制器的save函数中,我添加了以下代码:

            //$jform = $jinput->get(jform, null);
            $pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);
            $jform = $_POST['jform'];
            $tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
            $merged_jform = array_merge($jform,$tmp_pdf_filename);
            $jinput->post->set('jform',$merged_jform);
第一行有$jinput的代码不起作用。我用$jinput尝试了很多方法,但都不管用。所以最后我直接使用了$u POST。当然,这不是正确的方法,但至少是可行的

这里是完整的功能保存:

    public function save()
{
    $jinput = JFactory::getApplication()->input;
    $files = $jinput->files->get('jform', null);

    $pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);

    if (!empty($pdf_filename)) {

        $pdf_path = JPATH_ROOT . '/images/upload_pdf';
        if (!JFolder::exists($pdf_path)) {
            $status = JFolder::create($pdf_path);
            if (!$status) {
                JError::raiseWarning(100, JText::_('could not create directory pdf'), '');
            }
        }
        $file_path = JPath::clean($pdf_path . '/' . strtolower($files['upload_pdf']['name']));

        $status = JFile::upload($files['upload_pdf']['tmp_name'], $file_path);
        if ($status) {
            //$jform = $jinput->get(jform, null);
            $jform = $_POST['jform'];
            $tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
            $merged_jform = array_merge($jform,$tmp_pdf_filename);
            $jinput->post->set('jform',$merged_jform);
        } else {
            JError::raiseWarning(100, JText::_('could not copy pdf'), '');
        }
    }
    return parent::save();
}
试试这个…这是真正的方法


这应该能奏效。$file数组然后保存以下键:

error
name
size
tmp_name
type

这应该能奏效。$file数组然后保存以下键:error name size tmp_name type
    jimport('joomla.application.component.controlleradmin');
jimport('joomla.application.component.controllerform');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');

class JobControllerJob extends JControllerForm
{
    public function save()
    {
        $jinput = JFactory::getApplication()->input;
        $files = $jinput->files->get('jform', null);

        $files['upload_pdf']['name'] = JFile::makeSafe($files['upload_pdf']['name']);

        if (!empty($files['upload_pdf']['name'])) {

            $pdf_path = JPATH_ROOT . '/images/upload_pdf';
            if (!JFolder::exists($pdf_path)) {
                $status = JFolder::create($pdf_path);
                if (!$status) {
                    JError::raiseWarning(100, JText::_('could not create directory pdf'), '');
                }
            }   
            $file_path = JPath::clean($pdf_path . '/' . strtolower($files['upload_pdf']['name']));

            $status = JFile::upload($files['upload_pdf']['tmp_name'], $file_path);
            if (!$status) {
                JError::raiseWarning(100, JText::_('could not copy pdf'), '');
            }
        }
        return parent::save();
    }
}
            //$jform = $jinput->get(jform, null);
            $pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);
            $jform = $_POST['jform'];
            $tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
            $merged_jform = array_merge($jform,$tmp_pdf_filename);
            $jinput->post->set('jform',$merged_jform);
    public function save()
{
    $jinput = JFactory::getApplication()->input;
    $files = $jinput->files->get('jform', null);

    $pdf_filename = JFile::makeSafe($files['upload_pdf']['name']);

    if (!empty($pdf_filename)) {

        $pdf_path = JPATH_ROOT . '/images/upload_pdf';
        if (!JFolder::exists($pdf_path)) {
            $status = JFolder::create($pdf_path);
            if (!$status) {
                JError::raiseWarning(100, JText::_('could not create directory pdf'), '');
            }
        }
        $file_path = JPath::clean($pdf_path . '/' . strtolower($files['upload_pdf']['name']));

        $status = JFile::upload($files['upload_pdf']['tmp_name'], $file_path);
        if ($status) {
            //$jform = $jinput->get(jform, null);
            $jform = $_POST['jform'];
            $tmp_pdf_filename = array('upload_pdf' => $pdf_filename);
            $merged_jform = array_merge($jform,$tmp_pdf_filename);
            $jinput->post->set('jform',$merged_jform);
        } else {
            JError::raiseWarning(100, JText::_('could not copy pdf'), '');
        }
    }
    return parent::save();
}
$jinput = JFactory::getApplication()->input;
$files = $jinput->files->get('jform');
$file = $files['upload_pdf'];
error
name
size
tmp_name
type