Welcome Guest, Not a member yet? Register   Sign In
Problem with HTML URLs
#1

[eluser]nima72[/eluser]
Hi, I am developing a small website with a news section. in this news section I am using tinymce for adding the news and some of these news have multiple pictures in them, I have copied the pictures in a working directory but I cannot use relative path, and since I am getting the news out of database, I cannot use PHP in it.

whenever using the relative path for images I have the problem of methods and... cause html counts them as directories.
I'd rather not use absolute path since we are trying to get a separate domain, and if so, by changing the absolute directory I would have to change all the news data store in database.
is there anything I can do to solve this problem ?

***right now site is stored in http://www.main-site.com/ci and I want to be able to change it to http://another-site/ and not have to change all the news data.
#2

[eluser]goFrendiAsgard[/eluser]
Can you please provide more information (how do you write the link and where is the image location)?
Aside from that, maybe you can use base_url() function
#3

[eluser]nima72[/eluser]
for example I am trying to access image1.jpg in the same folder as index.php is, any relative path I use for would affect the link when trying to access the page on different methods, and even if I make it suitable for one method, if I try to pass an argument to the functions link would not be visible anymore.
and I cannot use base_url() since it is a php function and connot be accessed within database.
#4

[eluser]davidMC1982[/eluser]
The easiest way is to store everything after your base_url in the database, then use base_url(). So if http://www.example.com is your base_url and your images are in http://www.example.com/images/image_name.png you would store images/image_name.png in your db.

Code:
<img src="&lt;?php echo base_url('$result['image_name']);?&gt;">

Or you can just store the image_name.png in your db and do this:

Code:
<img src="&lt;?php echo base_url('images/' . $result['image_name']);?&gt;">

Or you could make your site more flexible, create a config file with the url for the images stored in it and then do:

Code:
<img src="&lt;?php echo base_url($this-&gt;config-&gt;item('image_url') . $result['image_name']);?&gt;">

Just be careful when storing urls etc that you're consistent with leading/trailing /'s. I think the convention in Codeigniter is to store with a trailing /.

And for your tiny_mce scripts, you might need to convert the urls. See the tiny_mce documentation referring to urlconvertor_callback. Remember, you can use php within your javascript.

Code:
var url = &lt;?php echo base_url();?&gt;
#5

[eluser]nima72[/eluser]
Thanks for your reply david

The problem is that when I insert
<img src="&lt;?php echo base_url('$result['image_name']);?&gt;">
in my code, it doesn't parse the PHP, it outputs something crazy

for example I used
<img src="&lt;?php echo base_url('image1.jpg');?&gt;">
for my code but the URL I got for the image1.jpg is
/index.php/&lt;?php echo base_url('image1.jpg');?&gt;

how can I fix it ?

Thanks in advance
#6

[eluser]nima72[/eluser]
Thanks for your reply david

The problem is that when I insert
Code:
<img src="&lt;?php echo base_url('images/' . $result['image_name']);?&gt;">
in my code, it doesn't parse the PHP, it outputs something crazy

for example I used
Code:
<img src="&lt;?php echo base_url('image1.jpg');?&gt;">
for my code but the URL I got for the image1.jpg is
Code:
/index.php/&lt;?php echo base_url('image1.jpg');?&gt;

how can I fix it ?

Thanks in advance
#7

[eluser]goFrendiAsgard[/eluser]
How could that be, do you mean that php is not parsed?
What do you get when you write this:
Code:
&lt;?php
echo base_url('image_1.jpg');
?&gt;
#8

[eluser]nima72[/eluser]
because it is pulled out of database it is now parsed due to security issues...
and in my latest post I describe what I get back if I do that PHP echo
#9

[eluser]goFrendiAsgard[/eluser]
Sorry nima72, I don't meant something bad, but the result you have post is just doesn't make sense for me.
As long as I know, there is no way the php will not be parsed, except you do something like this:
Code:
&lt;?php
    echo '<img src="&lt;?php echo base_url('image1'); ?&gt;" />';
?&gt;
Which I believe is not the case.

Can you please show the controller and the view code?
Maybe we can get a clue to help you




Theme © iAndrew 2016 - Forum software by © MyBB