So I was watching a video on how to upload photos using codeigniter. The link I used is here and the code is also at this site http://code.tutsplus.com/tutorials/codeigniter-from-scratch-file-uploading-and-image-manipulation--net-9452. I got everything to work however, when I tried to use the code on my own website I ran into a problem.
Basically all I changed was that I created a template for the view to be loaded in instead of just loading a single view. There is a controller Gallery.php file that looks like the follows.
<?php
class Gallery extends CI_Controller {
function index() {
$this->load->model('Gallery_model');
if ($this->input->post('upload')) {
$this->Gallery_model->do_upload();
}
$data['images'] = $this->Gallery_model->get_images();
$this->load->view('gallery_view',$data);
}
}
I simply changed this code to. Really only changing the last line and replacing it with those new three bottom lines.
<?php
class Gallery extends CI_Controller {
function index() {
$this->load->model('Gallery_model');
if ($this->input->post('upload')) {
$this->Gallery_model->do_upload();
}
$data['images'] = $this->Gallery_model->get_images();
$var = $this->load->view('gallery_view',$data,true);
$data['center_content'] = $var;
$this->load->view('includes_main/template',$data);
}
}
Now I get an strange error that I do not understand and no error shows up in the console log. Here is a picture of the error. http://i.imgur.com/tsKNj9W.png. The error says "unable to load the requested file" then doesn't have any file name after it. then there is a .php at the bottom of the page. I just don't have a clue what is giving me this error. I checked my template over again and again, but don't see anything wrong.
My template is as follows. I commented out everything just to make sure nothing else was giving me this error. So I am just left with one line.
<?php $this->load->view($center_content); ?>
Thanks for reading. Sorry I just have been stuck on this for a while and still haven't been able to fix it.
In this case there there are many mistakes. you did not load upload library and you also did not set config array. you can find on codeigniter user guide how to upload a file. I recommend to you read this link to upload a file in codeigniter
https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
Related
I'm working on a web application using Laravel 5.8, I'm new to Laravel framework. I would like to display PDF documents on the browser when users click on some buttons. I will allow authenticated users to "View" and "Download" the PDF documents.
I have created a Controller and a Route to allow displaying of the documents. I'm however stuck because I have a lot of documents and I don't know how to use a Laravel VIEW to display and download each document individually.
/* PDFController*/
public function view($id)
{
$file = storage_path('app/pdfs/') . $id . '.pdf';
if (file_exists($file)) {
$headers = [
'Content-Type' => 'application/pdf'
];
return response()->download($file, 'Test File', $headers, 'inline');
} else {
abort(404, 'File not found!');
}
}
}
/The Route/
Route::get('/preview-pdf/{id}', 'PDFController#view');
Mateus' answer does a good job describing how to setup your controller function to return the PDF file. I would do something like this in your /routes/web.php file:
Route::get('/show-pdf/{id}', function($id) {
$file = YourFileModel::find($id);
return response()->file(storage_path($file->path));
})->name('show-pdf');
The other part of your question is how to embed the PDF in your *.blade.php view template. For this, I recommend using PDFObject. This is a dead simple PDF viewer JavaScript package that makes embedding PDFs easy.
If you are using npm, you can run npm install pdfobject -S to install this package. Otherwise, you can serve it from a CDN, or host the script yourself. After including the script, you set it up like this:
HTML:
<div id="pdf-viewer"></div>
JS:
<script>
PDFObject.embed("{{ route('show-pdf', ['id' => 1]) }}", "#pdf-viewer");
</script>
And that's it — super simple! And, in my opinion, it provides a nicer UX for your users than navigating to a page that shows the PDF all by itself. I hope you find this helpful!
UPDATE:
After reading your comments on the other answer, I thought you might find this example particularly useful for what you are trying to do.
According to laravel docs:
The file method may be used to display a file, such as an image or PDF, directly in the user's browser instead of initiating a download.
All you need to do is pass the file path to the method:
return response()->file($pathToFile);
If you need custom headers:
return response()->file($pathToFile, $headers);
Route::get('/show-pdf/{id}', function($id) {
$file = YourFileModel::find($id);
return response()->file(storage_path($file->path));
})->name('show-pdf');
Or if file is in public folder
Route::get('/show-pdf', function($id='') {
return response()->file(public_path().'pathtofile.pdf');
})->name('show-pdf');
then show in page using
<embed src="{{ route('show-pdf') }}" type="text/pdf" >
thx for helping me on this :)
Im developping a serie of test on a symfony app with Symfony/Panther. Im looking for a way to test if my logo redirect to the correct page. The way I see it, is I have to test the link and then click on it to test the redirection.
The panther documentation is quiet specific about link testing see here:
https://symfony.com/blog/introducing-symfony-panther-a-browser-testing-and-web-scraping-library-for-php
I also saw how to find an image via DomCrawler np with that...
SO what I have tried, is to adapt the link testing method to an image, of course it didnt work cause the image is not a string as expected by the method
So if someone have an idea how to test the redirection on a image link It ll be awesome. Thx in advance
<?php
namespace App\Tests;
use Symfony\Component\Panther\PantherTestCase;
class assertLogoRedirectTo extends PantherTestCase
{
public function test()
{
$client = static::createPantherClient();
$crawler = $client->request('GET','https://my.sibluconnect.com');
$client->waitFor('.login');
$image = $crawler->selectImage('siblu')->image();
$link = $crawler->selectLink($image)->link();
$crawler = $client->click($link);
}
}
Running the test shows this error:
DevTools listening on
ws://127.0.0.1:12947/devtools/browser/d3a0e57f-2b00-4eb3-97e3-64986cf0495e
E 1
/ 1 (100%)/test1//test2//test3//test4/
Time: 11.17 seconds, Memory: 38.00MB
There was 1 error:
App\Tests\assertLogoIsvisible::test Object of class
Symfony\Component\Panther\DomCrawler\Image could not be converted to
string
Edit on my post...I found the way to do it.
A image is not a link, a link is a <a href> or <button> so the test shoudnt be looking for a image to be a link. So Ive try another method which is trying to target the link via its position in the page. As this link is my logo it is the first <a href> on the page.
Here's the code Ive tried and it works just fine !!!
namespace App\Tests;
use Symfony\Component\Panther\PantherTestCase;
class assertLogoRedirectTo extends PantherTestCase // Success
{
public function test()
{
echo'/test1/';
$client = static::createPantherClient();
$crawler = $client->request('GET', 'https://my.sibluconnect.com/fr/');
$link = $crawler->filter('a')->eq(0)->attr('href');
$crawler = $client->request('GET',$link);
$this->assertSame('http://sibluconnect.com/', $client->getCurrentURL());
}
}
Hope it helps someone in the futur ;)
I have an extension that overrides getSkinUrl() and intercepts images coming through it, makes changes, then continues. This works for any images referenced in PHTML files.
However, This isn't catching images in CMS blocks. In the CMS blocks, I'm using
{{skin url="images/your_amazing_image.gif"}}
Magento's template variables are defined in the following file.
app/code/core/Mage/Core/Email/Template/Filter.php
For the {{skin}} variable, the following code is used around line 264 in filter.php
public function skinDirective($construction)
{
$params = $this->_getIncludeParameters($construction[2]);
$params['_absolute'] = $this->_useAbsoluteLinks;
$url = Mage::getDesign()->getSkinUrl($params['url'], $params);
return $url;
}
I'm not sure how you are overriding getSkinUrl, but make sure that the getSkinUrl method is the same method you are overriding.
I'm trying to create my first component for Joomla 2.5 but when try to execute get this error:
Error: 500
You may not be able to visit this page because of:
an out-of-date bookmark/favourite
a search engine that has an out-of-date listing for this site
a mistyped address
you have no access to this page
The requested resource was not found.
An error has occurred while processing your request.
View not found [name, type, prefix]: transportation, html, transportationView
What I've developed now is very basic and this is the controller under site/components/com_transportation/controllers/controller.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
class TransportationController extends JController {
}
And under site/components/com_transportation/views/view.html.php this:
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
class TransportationViewTransportation extends JView {
// Overwriting JView display method
function display($tpl = null) {
// Assign data to the view
$this->msg = 'Hello World';
// Display the view
parent::display($tpl);
}
}
What I'm missing? What is wrong?
Your folder structure is incorrect. Your view file must be in site/components/com_transportation/views/transportation/view.html.php
Try this ,
When you start developing a new component go through the tutorial deeply,Then start modifying the samples .
follow this url it will help you .Its for 1.5 but the things are same for 2.5.
Only you have to mention version in the xml
<install type="component" version="1.5.0">
Also you will get a sample component download from this.
Download it and compare with your component then find the issue.
Hope this may helps..
View not found [name, type, prefix]: transportation, html, transportationView
Means just tha no view was found with the class name of transporationViewtransporation and the type view.html.php. What is the name of the class in your view.html.php file? is the second transportation really lower case like that? Also what are the name(s) of your layout and xml files in the tmpl folder?
I am having trouble simply making multiple pages with CodeIgniter. For example, I am trying to make a simple About page with codeigniter. So I create an about.php controller and an about_view.php view file. However if I were to try and make a link from the home page to "http://miketrottman.com/about" it will go nowhere. I am sure I am fundamentally missing something but I have read and watched example videos I am just spinning my wheels on this project at this point. Here is my home.php controller, let me know if I should post any other code. My site is http://miketrottman.com. I am new to the CodeIgniter scene an any help is much appreciated!
home.php in Controller directory
'
class Home extends Controller {
function Home()
{
parent::Controller();
}
function index()
{
//Load Extensions
$this->load->database();
$this->load->library('session');
//Include these basics everytime the home page is loaded
$data['pageTitle'] = "Trottman's Blog";
$data['title'] = "Trottman's Blog Title";
$data['heading'] = "Trottman's Blog Heading";
//Load Proper CSS for users browser
$data['css'] = $this->getCSS();
//Load the Blog Model
$this->load->model('blog_model');
//Load the Blog Entries
$data['blog'] = $this->blog_model->getBlogEntries();
$data['blog_comments'] = $this->blog_model->getBlogCommentEntries();
//
//Load all of this information into the home_view Page
$this->load->view('home_view', $data);
}
function getCSS()
{
//Load user_agent library to pull user's browser information
$this->load->library('user_agent');
//Agent is now the users browser
$agent = $this->agent->browser();
//According to the users browser, this is what the CSS should be
if ($agent == 'Internet Explorer')
{
$cssFile = "ieStyle.css";
}
else
{
$cssFile = "style.css";
}
return $cssFile;
}
}?>
'
And I am dumb, my whole problem was I was trying to go to /about and what I should have been doing is http://miketrottman.com/index.php/about because I have yet to remove the index.php in my URIs.
So I guess, thanks Stack overflow for creating an outlet for my ignorance, perhaps others can learn from my mistake then!