Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6701319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:12+00:00 2026-05-26T06:55:12+00:00

I am new to cakePHP and I am tring the blog example of cakePHP

  • 0

I am new to cakePHP and I am tring the blog example of cakePHP 1.3 book .
I correctly upload image in this blog example.The image name in database and image in DOCUMENT_ROOT/….correctly
but now I am wanted to show image in my blog with related post.

I am using this code for image upload…

 function add() {

if (!empty($this->data)) {
    if(isset($this->data["Image"]["image"]["name"])){
        $file = new File($this->data["Image"]["image"]["name"]);
        $ext = $file->ext();

        if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
 $this->Session->setFlash('You may only upload image files.');
        }else{
         if(move_uploaded_file($this->data["Image"]["image"]                ["tmp_name"],$_SERVER["DOCUMENT_ROOT"]."test_om/blog/app/webroot/img/upload_image/"
                 . $this->data["Image"]["image"]["name"]) == true){
             $this->data["Post"]["image"] =  $this->data["Image"]["image"]["name"];
         }

    $this->Post->save($this->data);
    $this->Session->setFlash('Your post has been saved.');
        $this->redirect(array('action' => 'index'));
                    }
    }
  }

 } 

and i am showing image form this code

       <?php echo $this->Html->image('/img/upload_image/1.gif'); ?>

and this show same image with all post.
but i am wanted to set specfic image with its related post….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:55:13+00:00Added an answer on May 26, 2026 at 6:55 am

    If you are sure you are getting everything correct (in the database and the file where it should be) you should use something like this in the view.

    <?php echo $this->Html->image($this->data['Post']['image']); ?>
    

    this is assuming you are passing the data from the controller in the way described in the tutorial to a view view 🙂

    if is an index view you should have a variable posts that have all post info, and in the view you will be in a loop like a foreach ($post as $post). Assuming this your view should have something like this:

    <?php echo $this->Html->image($post['Post']['image']); ?>
    

    Suggestion: use debug kit (cakephp plugin) so you can see what variables are passed down and the structure (like a pr($variable))

    Hope all this helps you, if not, comment this post so i can try to extend my answer if needed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I'm new to cakephp, but from what I understand all of the database interaction
So I'm new at this whole CakePHP thing, but I'm looking to get the
(New to CakePHP, so this may be an obvious thing, but I was unable
I'm new to CakePHP but I've been though their FAQs and guides to no
I'm new to CakePHP and am just running through the configuration process, but am
I'm pretty new to CakePHP but I think I'm starting to get the hang
I'm trying to get this loop to save a new record to the database
Okay, so I'm fairly new to CakePHP. This is the setup: I've got a
i'm very new to this cakephp & i got an assignment to fix an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.