我有以下代码:
ArrayList<FileInfo> mDataSource;
DateFormat mDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT, Locale.getDefault()); // one instance, no needed to be recreated each time
...
public void addFiles(String path) {
if (!mDataSource.isEmpty())
mDataSource.clear();
boolean showhidden = Settings.showHiddenFiles();
final File file = new File(path);
// based on source from SimpleUtils
if (file.exists() && file.canRead()) {
File[] list = file.listFile(); //get list of File object, rather than list of String
// add files/folder to ArrayList depending on hidden status
for (File aList : list) {
String fileName = aList.getName();
boolean isFile = aList.isFile();
boolean isDir = aList.isDirectory();
if ((isFile || isDir) && (showhidden || (fileName.charAt(0) != '.'))) {
FileInfo fileInfo = new FileInfo();
fileInfo.mName = fileName;
fileInfo.mIsFile = isFile;
if (isFile) {
fileInfo.mLength = aList.length();
} else {
fileInfo.mLength = aList.list().length;
}
fileInfo.mLastModified = mDateFormat.format(aList.lastModified());
IconPreview.getFileIcon(aList, fileInfo.mIcon);
mDataSource.add(fileInfo);
}
}
} else if (Settings.rootAccess()) {
//TODO make the same for root access
} else {
Toast.makeText(mContext, mContext.getString(R.string.cantreadfolder), Toast.LENGTH_SHORT).show();
}
// sort files with a comparator if not empty
if (!mDataSource.isEmpty()) {
Collections.sort(mDataSource, new Comparator<FileInfo>() {
@Override
public int compare(FileInfo lhs, FileInfo rhs) {
return lhs.mName.toLowerCase().compareTo(rhs.mName.toLowerCase());
}
});
}
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder mViewHolder;
int num_items = 0;
final FileInfo file = mDataSource.get(position);
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT, Locale.getDefault());
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_browserlist, parent,
false);
mViewHolder = new ViewHolder(convertView);
convertView.setTag(mViewHolder);
} else {
mViewHolder = (ViewHolder) convertView.getTag();
}
if (Settings.getListAppearance() > 0) {
mViewHolder.dateview.setVisibility(TextView.VISIBLE);
} else {
mViewHolder.dateview.setVisibility(TextView.GONE);
}
if (Settings.getListAppearance() > 0) {
if (file.mIsFile)) {
// Shows the size of File
mViewHolder.bottomView.setText(SimpleUtils.formatCalculatedSize(file.mLength));
} else {
// show the number of files in Folder
mViewHolder.bottomView.setText(file.mLength
+ mResources.getString(R.string.files));
}
}
mViewHolder.topView.setText(file.mName);
mViewHolder.dateview.setText(file.mLastModified);
return convertView;
}
我想在<div id="bannerBg">
<div id="containingDiv">
<div id="banner-fade">
<ul class="bjqs">
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/8962835311407882364.jpg">
</li>
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/15717527901407876556.jpg">
</li>
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/5158579491407874706.jpg">
</li>
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/20067615141407882364.jpg">
</li>
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/17148640751407882364.jpg">
</li>
<li>
<img alt="bannerimage" class="slider-image" src="http://yousounds.com/admin/img/gallery/original/16658741621407876556.jpg">
</li>
</ul>
</div>
</div>
</div>
中找到此代码。我是code igniter
的新手,我不知道如何启动,而且大多数代码都不在浏览器中运行,因为不允许直接访问。有人请帮帮我。
答案 0 :(得分:1)
首先创建一个文件并将其保存在控制器文件夹中,其名称如say.php(如果你使用CI 3.X,它应该是Image.php,否则它将不起作用。)。然后在routes.php文件中将其设置为默认控制器(您可以在config文件夹中找到它)。控制器文件的代码应该是这样的:
<?php
//if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Image extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('image'); // name of your html file whose code you have written above.
}
}
?>
并更改此http://yousounds.com/admin/img/gallery/original/17148640751407882364.jpg
进入
<?php echo base_url(); ?>img/gallery/original/17148640751407882364.jpg
答案 1 :(得分:0)
如果您想要CI中的图像路径,请使用
src="<?php echo base_url()?>admin/img/gallery/original/8962835311407882364.jpg"
所以你的最终代码将是
<img alt="bannerimage" class="slider-image" src="<?php echo base_url()?>admin/img/gallery/original/8962835311407882364.jpg">
然后文件结构将(根据您的src
)
- admin
- img
- gallery
- original
- 8962835311407882364.jpg
注意:要使用base_url()
,请在config/config.php
$config['base_url'] = '';
$config['index_page'] = '';