0
A
回答
0
form xml :
<field name="con_image" type="file" label="" description="" hint="Image"/>
default.php
<div class="controls">
<?php if (!empty($this->item->con_image) && file_exists(JPATH_SITE.'/images/contact_image/thumb_' . $this->item->con_image)) : ?>
<img src="<?php echo JRoute::_(JUri::root() . 'images/contact_image/thumb_' . $this->item->con_image, false);?>">
<?php endif; ?>
<input type="hidden" name="jform[con_image]" id="jform_image_hidden" value="<?php echo $this->item->con_image; ?>" />
<?php echo $this->form->renderField('con_image'); ?>
</div>
your view table file code for image upload:
$files = $app->input->files->get('jform', array(), 'raw');
$array = $app->input->get('jform', array(), 'ARRAY');
if (!empty($files['con_image']['name']))
{
// Deleting existing files
$oldFiles = PlansHelpersPlans::getFiles($this->id, $this->_tbl, 'con_image');
foreach ($oldFiles as $f)
{
$oldFile = JPATH_ROOT . '/images/contact_image/' . $f;
if (file_exists($oldFile))
{
unlink($oldFile);
}
}
$this->con_image = "";
$singleFile = $files['con_image'];
jimport('joomla.filesystem.file');
// Check if the server found any error.
$fileError = $singleFile['error'];
$message = '';
if ($fileError > 0 && $fileError != 4)
{
switch ($fileError)
{
case 1:
$message = JText::_('File size exceeds allowed by the server');
break;
case 2:
$message = JText::_('File size exceeds allowed by the html form');
break;
case 3:
$message = JText::_('Partial upload error');
break;
}
if ($message != '')
{
$app->enqueueMessage($message, 'warning');
return false;
}
}
elseif ($fileError == 4)
{
if (isset($array['con_image']))
{
$this->con_image = $array['con_image'];
}
}
else
{
// Replace any special characters in the filename
jimport('joomla.filesystem.file');
$filename = JFile::stripExt($singleFile['name']);
$extension = JFile::getExt($singleFile['name']);
$filename = preg_replace("/[^A-Za-z0-9]/i", "-", $filename);
$filename = rand()."-".$filename . '.' . $extension;
$uploadPath = JPATH_ROOT . '/images/contact_image/' . $filename;
$fileTemp = $singleFile['tmp_name'];
if (!JFile::exists($uploadPath))
{
if (!JFile::upload($fileTemp, $uploadPath))
{
$app->enqueueMessage('Error moving file', 'warning');
return false;
}
}
//$this->con_image .= (!empty($this->con_image)) ? "," : "";
$this->con_image = $filename;
}
}else{
$this->con_image = $array['con_image'];
}
你仍然有問題,那麼請在這裏 下載我簡單的組件:https://github.com/erakashpatel/Important-notes/blob/master/com_helloworld.zip 或 https://github.com/erakashpatel/Important-notes/blob/master/com_test.zip
我希望它作品。提前感謝。
0
for xml :
Joomla File form field type in xml:
https://docs.joomla.org/File_form_field_type
<field name="myfilevalue" type="file" label="Enter some text" description="Choose an image from your computer with maximum 100KB" size="10" accept="image/*" />
OR
if your file field in html form then used :
<input type="file" name="jform[myfilevalue]" >
我希望它的幫助, 別人提供更多介紹請
相關問題
- 1. Java applet,將jar文件添加到清單文件
- 2. 通過清單文件添加Spring配置文件到classpath
- 3. 使用python將字段添加到文本文件中的列
- 4. 我可以將清單文件添加到別人的exe文件嗎?
- 5. 找出誰將READ_PHONE_STATE添加到我的清單文件?
- 6. 使用Gradle將屬性添加到jar文件的清單
- 7. ANDROID:無法將android:theme =「@ android:style/Theme.Black.NoTitleBar.Fullscreen」添加到清單文件
- 8. 如何將angularMoment添加到Rails清單文件?
- 9. 通過清單文件將面板添加到editviewdefs.php
- 10. 我應該將基礎活動添加到清單文件嗎?
- 11. 如何使用mt.exe將清單添加到可執行文件?
- 12. HTML5:爲什麼我需要將清單文件添加到.htaccess?
- 13. Jade-lang添加清單文件
- 14. Gradle - 將單個文件添加到JAR
- 15. 將java文件添加到jsp文件
- 16. 將html文件添加到manifest.json文件
- 17. 將文字添加到標籤控件
- 18. STSDev不向清單文件添加文件
- 19. 將行添加到文件
- 20. 將文件添加到.apk
- 21. 將html添加到文件
- 22. 將文件添加到MSI
- 23. 將Excel文件和.TXT文件添加到XPages中的相同字段
- 24. 將文本字段驗證添加到多個文本字段
- 25. 如何將文件附加到輸入類型文件字段
- 26. 如何將文件追加到文件輸入字段
- 27. RestSharp AddFile將多部分表單頭文件添加到文件
- 28. phpmyadmin將文本添加到空字段?
- 29. MySQL:將文本添加到字段
- 30. phpmyadmin將文本添加到字段
嗨,謝謝你的回答。這就是我已經擁有的。我想要做的就是能夠上傳該文件。爲了做到這一點,我需要將'
@simon:您可以嘗試使用Javascript設置enctype,如此處所述 - http:// www .w3schools.com/jsref/tryit.asp?文件名= tryjsref_form_enctype2 – Irfan