Jump to content

path to images - html/php


vansant

Recommended Posts

I'm creating a website for a family member.  I'm not an html or php expert, just dabble enough until things look and feel right.  I'm stuck on something and wondered if what I need is even possible - or maybe other ideas for what I'm trying to do.

 

My folks are no good at any type of code, so keeping this simple is important.  I've created a directory for my parents to log directly in and only view the pages that they can edit.  This is their base directory in their ftp.  (This would be referred to as /parentsfiles below)

 

I'm using php to include the /parentsfiles/xxx.html file to create the body of the page (the part that changes frequently, and is editable by the folks).

 

/parentsfiles

/parentsfiles/index.html

/parentsfiles/about.html

/parentsfiles/contact.html

/parentsfiles/image.jpg

index.php

about.php

contact.php

 

For simplicity, lets say the above structure is what you'd see upon FTP in.  The index.php file contains all the real code for that page, the css, the menu, any other scripting - and the /parentsfiles/index.html file contains what their simple WYSIWYG editor creates for the body (no real html to speak of).  This is to keep them from messing up the code of the main page.  Follow?

 

Now, when they upload an image (/parentsfiles/image.jpg) and call that image in their page, it doesn't bring it up.  Of course it's looking for it in the base directory, not in the /parentsfiles/ directory where they've put it. 

 

THE QUESTION:

Any code I can use in the index.php page to ensure all of the images include /parentsfiles/?  Remember, I'm trying to make this simple for my parent's side, I'd rather do a bunch of work on my side to save them the hassle.

OR - am I doing this the wrong way?  Any other ideas to protect the valuable portions of the site while giving them free reign to their files and images?

Link to comment
https://forums.phpfreaks.com/topic/196814-path-to-images-htmlphp/
Share on other sites

Sure, so the backend script writes the data to a html file, right? Well just before it actually writes to the file you should do a search for

 

<img src="

 

and replace it with

 

<img src="http://mysite.com/

 

That way the end result will be

 

<img src="http://mysite.com/imagefolder/image.jpg" />

 

To do this you need to use the str_replace function, I'm assuming the variable $body represents the HTML

 

$body = str_replace('<img src="', '<img src="http://mysite.com/', $body);

well there's two files.  For instance:

 

index.php -> this file contains the html, css, and code for the page.  It uses the virtual command to bring in the body

 

parentssite/index.html -> this file contains just the body text.  no css, no code, nothing but the output of their editor.

 

Also in the parentssite/ directory will be the images that they upload.

 

If you'd like to chat offline, let me know and I'll pass you my info

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.