Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to display images in the view #30

Closed
lawrence615 opened this issue Jan 22, 2013 · 7 comments
Closed

Not able to display images in the view #30

lawrence615 opened this issue Jan 22, 2013 · 7 comments

Comments

@lawrence615
Copy link

Hi,

I am trying to use this plugin to upload pictures in a website that am building but am encountering some challenges.

First off when i execute the command "cake Media.Media init", this is what happens
1

The image above shows that the transfer directory is been created outside the webroot directory. When I upload images there been saved in that directory.

Now the problem comes when I try to display, the view does not get the image in the path specified as it tends to check in webroot folder. It does not find the transfer directory and thus displays nothing.

Please help

@bmcclure
Copy link
Owner

Posted to your message in the other ticket, but this is probably a better place:

The transfer directory shouldn't be used for displaying images--once the upload completes successfully, they should be in your app\webroot\media\static, or app\webroot\media\filter directory (if you are modifying them with filters). Can you post your config for Media?

@ThatGirlSlays
Copy link

The same thing is happening to me. I have been uploading test photos and they are going to app/Media/transfer/img (the plugin will create these directories if they do not exist). However, the code for the view.ctp was provided as...

Html->image( '../Media/transfer/img/' . h($employee['User']['basename']), array('alt' => __('Profile Picture'), 'border' => '0')); ?>

When I view my page and look at the source code, I can see that the path of the image is pointing to "/cake-directory/img/../Media/transfer/img/filaname.jpg"

In my users table in my DB, the file column for the recently created user is "/home/user/public_html/cake-directory/app/Media/transfer/img/filename.jpg"

these are clearly not the same address. I would like for my images to rest inside of the webroot, but how do I fix this?

@ThatGirlSlays
Copy link

First I would like to say that I JUST joined github specifically so I could follow this thread so I apologize if there is a certain way of formatting code on here that I'm not aware of...

But I think I figured out a if not the solution. I'm on cake 2.2.4 btw.

In the Media bootstrap file, change the following...

line 107: define('MEDIA_TRANSFER', APP. 'Media' . DS . 'transfer' . DS);
to: define('MEDIA_TRANSFER', MEDIA . 'transfer' . DS);
what it did before: when you upload a photo is goes straight to "/relative/path/to/cake/App/Media/transfer/img". It created the directory if it did not exist.
what the change did: uploads photo to "/relative/path/to/cake/App/webroot/media/transfer/img"
note: there was also a discrepancy in that line 98 and in the database has media with a lowercase m and line 107 had media with an uppercase m.

line 119: define('MEDIA_URL', 'media/');
to: define('MEDIA_URL', WWW_ROOT . 'media/');
umm: I don't recall what this actually did but it was required in order for it to work lol. Now all the files upload to webroot/media/transfer/img"

use in your view

Html->image('../media/transfer/img/' . h($user['User']['basename']), array('alt' => __('title goes here'), 'border' => '0')); ?>

The html helper image function automatically looks in "/relative/path/to/cake/App/webroot/img/" so you need the "../" to go up a directory to the webroot where the media directory now lies.

@gBokiau
Copy link

gBokiau commented Jan 24, 2013

@bhndbrwneyes The docs are indeed misleading. The recommended method is to use the plugin's MediaHelper instead of the default HtmlHelper. It will automatically find the file's location based on your configuration. To get the uploaded file, use:

$this->Media->embed('img/filename.jpg');

to get one the 'filtered' versions, use :

$this->Media->embed('l/img/filename.jpg');

@lawrence615
Copy link
Author

Hey bhndbrwneyes,
Thanks a lot for your help, I did exactly as you explained and finally I was able to upload and display an image using this plugin.

@lawrence615
Copy link
Author

Hey gBokiau,

When I used your approach, I got an error of Missing Helper

@lawrence615
Copy link
Author

I just remembered that that was not the only problem I encountered when trying to use the plugin.

Initially I got an error when I added the line "require APP . 'Plugin' . DS . 'Media' . DS . 'Config' . DS . 'core.php';" in the app bootstrap. I changed to "require APP . 'Plugin' . DS . 'Media' . DS . 'Config' . DS . 'bootstrap.php';" as I realized the core.php file was missing

This was not part of the issue I had raised but I know it might help someone.

Thanks all for your time and help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants