I want to display a directory that contains only PDF's. I'd like the user to click on a given line and have the appropriate PDF displayed. I copied some code from this site and had to modify it. I put the "breaking return" tag so that each file would be displayed on a separate line. The following code works fine, but I need the file listings to be sorted alphabetically. I've tried the sort function for $thelist in several places, but I can't seem to get it to work. I appreciate your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if ($handle = opendir('hymn_lyrics')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= ''.$file.''.'<br />';
}
}
closedir($handle);
}
?>
<P>List of Hymns:</p>
<P><?=$thelist?></p>
</body>
</html>
I changed the code after reading another post here. This works fine:
<?php
$files = glob('hymn_lyrics/*.pdf', GLOB_BRACE);
foreach($files as $file)
{
if ($file != "." && $file != "..")
{
$thelist .= ''.$file.'<br />';
}
}
?>
<p>List of files:</p>
<p><?=$thelist?></p>
Related
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
#if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
#elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
#endif
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>.
Correction of your code:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
#if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
#elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
#endif
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]); and no if statement required
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
I am using a function I found on Stackoverflow to replace some special characters:
function toASCII( $str )
{
return strtr(utf8_decode($str),
utf8_decode(
'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű'),
'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou');
}
However, when I try the functionality in HTML I do not get the desired result. HTML code:
<?php
$test = 'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű';
$test1 = toASCII($test);
?>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php echo $test."<br>";
echo $test1;
?>
</body>
</html>
Result in Browser:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű
uuuuuuuYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYuusaaaaaaaceeeeiiiionoooooouuuuyyuu
Any ideas why some characters are shown as u instead of the desired one?
Note: I would prefer to avoid using setlocale since it would required additional changes in the code.
When you use strtr() with three arguments, it operates with bytes and not with multibyte characters (see http://php.net/manual/en/function.strtr.php#111270). Instead you have to give an array that contains an exact mapping.
This would be a solution for your case:
<?php
function mbStringToArray( $str ) {
return preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
}
function toASCII( $str ) {
$map = array_combine(
mbStringToArray('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű'),
mbStringToArray('SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou')
);
return strtr($str,$map);
}
$test = 'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű';
$test1 = toASCII($test);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
echo $test."<br>";
echo $test1;
?>
</body>
</html>
Output:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŐŰßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿőű
SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYOUsaaaaaaaceeeeiiiionoooooouuuuyyou
I'm new in codeigniter, I feel trouble about layout/template/themes in codeigniter.
I don't know when should using one of them..
What is the best way that i can do? if i want to make a website with free a html/css template like
goodnatured
|--img
|--img01.jpg
|--css
|--style.css
|--js
|--jquery.js
|--index.html
Anyone can tell me a tutorial, suggest, ... thanks
I just write little additional library(application/libraries/display_lib.php) for rendering tempates and similar page blocks.
Something like this:
class Display_Lib{
private $_CI;
private $_template_data;
public function __construct()
{
$this->_CI =& get_instance();
}
public function set($key, $value)
{
$this->_template_data[$key] = $value;
}
public function get($key)
{
return $this->_template_data[$key];
}
public function get_template_data()
{
return $this->_template_data;
}
public function display_page($view, $data = array())
{
$this->set('content', $this->_CI->load->view($view, $data, TRUE));
$this->_CI->load->view('templates/main_template', $this->get_template_data());
}
}
Set this library in auto load:
$autoload['libraries'] = array('session', 'database', 'display_lib');
And call it in controller:
class Main extends CI_Controller{
public function index()
{
$some_data = array();
$this->display_lib->display_page('views/main_view', $some_data);
}
}
Template example:
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<?=base_url();?>">
<meta charset="utf-8">
<link rel="icon" href="<?=site_url('img/favicon.ico')?>" type="image/x-icon"/>
<link rel="stylesheet" href="<?=site_url('css/style.css');?>" type="text/css" media="screen, projection"/>
<script type="text/javascript" src="<?=site_url('js/jquery-1.10.2.min.js');?>"></script>
<title>Some page title</title>
</head>
<body>
<header></header>
<div class="auth_wrapper">
<div class="content">
<?=$content;?>
</div>
<div class="buffer"></div>
</div>
<footer></footer>
</body>
</html>
And application/views/main_view simple exmaple:
<div>Come content will be here</div>
This lib allow to use templates and render views from controllers.
Templates handle the layout of your page. You create a template that will contain your meta, header, footer, and a space for the body. The body get injected in the template, this is where the content change.
The idea is that most of the site don't change, only the body changes. This is where templates are useful, they save you time and increase consistency.
See this template library, it's pretty good: http://getsparks.org/packages/template/show
Themes is combined with a template as templates often define the layout and a theme just 'skin' the layout. A theme include assets and styles that will modify the template further more.
Cheers
Make a template.php, header.php, footer.php. Below is template.php, Similarly make header and footer and place them all in views folder:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="<?=site_url('img/favicon.ico')?>" type="image/x-icon"/>
<link rel="stylesheet" href="<?=site_url('css/style.css');?>" type="text/css" media="screen, projection"/>
<script type="text/javascript" src="<?=site_url('js/jquery-1.10.2.min.js');?>"></script>
<title>Some page title</title>
</head>
<body>
<header><?=$this->load->view('header');?></header>
<div class="wrapper">
<div class="content">
<?=$main?>
</div>
</div>
<footer><?=$this->load->view('footer');?></footer>
</body>
</html>
In your Controller function:
function index(){
$data = array();
$data['main'] = "home"; #this view is home.php in views folder, the content part of template.php
$this->load->view('template', $data); #this is the template file being rendered.
}
This is the most simple way of using templates in CI I think.
i have integrated uploadify with codeigniter.i can't able select images while clicking the select photos.
MY View file
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<title>Uploadify V3 & CodeIgniter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Capsone-System2" >
<!-- Styles -->
<link href="/assets/bootstrap/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet"/>
<link href="<?php echo base_url;?>assets/js/jquery/uploadify_31/uploadify.css" type="text/css" media="screen" rel="stylesheet"/>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Content -->
<div class="container">
<h1 class="page-header">Uploadify V3 & CodeIgniter</h1>
<p>This is a simple tutorial demo showing Uploadify V3 working with CodeIgniter 2.1.2</p>
<?php echo form_open_multipart(); ?>
<ul class="unstyled">
<li>
<?php echo form_upload('userfile','','id="userfile"'); ?>
<?php echo (isset($error)) ? $error : ''; ?>
</li>
<li>
<?php echo form_button(array('content'=> 'Upload', 'id'=>'upload-file', 'class'=>'btn btn-large btn-primary')); ?>
</li>
</ul>
<?php echo form_close(); ?>
</div>
<!-- End Of Main Content -->
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>-->
<!--<script>window.jQuery || document.write('<script src="<?php echo base_url;?>assets/js/jquery/jquery-1.8.0.min.js"></script>')</script>-->
<script src="<?php echo base_url;?>assets/js/jquery/uploadify_31/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<!--<script src="<?php echo base_url;?>assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>-->
<script type="text/javascript">
$(document).ready(function () {
var base_url = '<?php echo base_url; ?>';
alert(base_url);
$('#upload-file').click(function (e) {
e.preventDefault();
$('#userfile').uploadify('upload', '*');
alert(base_url);
});
$('#userfile').uploadify({
'debug':true,
'auto':false,
'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
'uploader': base_url + 'uploadify_v3/do_upload',
'cancelImg': base_url + 'assets/javascript/jquery/uploadify_31/uploadify-cancel.png',
'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif',
'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif)',
'fileSizeLimit':'2MB',
'fileObjName':'userfile',
'buttonText':'Select Photo(s)',
'multi':true,
'removeCompleted':false,
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
}
});
});
</script>
</body>
</html>
My Controller File
I have error uncaught exception: Call to StartUpload failed
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* #property CI_Upload $upload
*/
class Uploadify_v3 extends CI_Controller
{
public $view_data = array();
private $upload_config;
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper(array('url', 'form'));
$this->load->view('uploadify_v3', $this->view_data);
}
public function do_upload()
{
$this->load->library('upload');
$image_upload_folder = FCPATH . '/uploads';
if (!file_exists($image_upload_folder)) {
mkdir($image_upload_folder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $image_upload_folder,
'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
'max_size' => 2048,
'remove_space' => TRUE,
'encrypt_name' => TRUE,
);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$file_info = $this->upload->data();
echo json_encode($file_info);
}
}
}
/* End of file uploadify_v3.php */
/* Location: ./application/controllers/uploadify_v3.php */
I have spent more time..still now i can't fix this error..please help me.
I too had the same problem, it was a security issue because I was hosting the flash .swf file on a separate domain eg: static.mysite.com
Make sure your swf file and post handler script are hosted on the same domain that you are accessing the site from.
Or if you need to add cross domain posting then see here:
http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html
How to get URL using Smarty similar to window.location in JavaScript ?
I did this
{$smarty.server.PHP_SELF}
but it's not working.
You can use this, too.
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
See what is available with this:
{$smarty.server|#var_dump}
A couple examples for url https://some.example.com/some/path?param=1:
{$smarty.server.SCRIPT_URI}
https://some.example.com/some/path
{$smarty.server.SERVER_NAME}
some.example.com
{$smarty.server.SCRIPT_URL}
/some/path
This is controller code :
<?php
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pro = 'https';
} else {
$pro = 'http';
}
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
$current_url = $pro."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
$smarty->assign("current_url",$current_url);
$smarty->display('index.tpl');
?>
You can display variable in index.tpl template file :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Title</title>
</head>
<body>
{$current_url}
</body>
</html>