John Davidson

javascript - Php preloads file when folder has certain name? what?

0 comments
Message:


I am making a html project. But had to use php, so updated it to that.


I have a header loaded in from a js-file, and in it, it links to another page (used to be blog.html, but now it is blog.php <- that is important to remember).




The problem begins here:


The header still tryes to get blog.html and any other changes to it doesn't apear eighter. Well, first I though I might have forgotten to link to the propper js-file. But no.


Then after a lot of trial and error, I ended up copying the whole folder (the original folder was called "portfolio", now it is "portfolio - Copy" <- also important)


In this new file. It works! It is Exactly the same content of the folders. Only difference is that it goes under a different name.


My conclution is that localhost saves the js-file under the "portfolio" folder, so it doesn't update the file for some reason. But I really don't know.


(btw. I can litterially delete the js-file. And nothing happens. Then if I go into the index.html file, and Ctrl-click the script that loads the js-file. It says that there is no file at this location. But if I then delete the completly useless script tag, the header doesn't load. What?)


Does anyone know what could be happening. Btw if you need a little more info, I might be able to give it, but I just can't think of much else relevense here.


Thanks in advance :)



My Answer:
to enable server-side processing). I want to preload the blog.php file when the user is on the homepage, but only if the folder containing the blog.php file has a certain name.

Here is an example of how you can achieve this using PHP:

php
$folderName = "blog"; // Specify the folder name here

if (basename(dirname(__FILE__)) == $folderName) {
echo '';
}
?>


In this code snippet, we first define the folder name that we want to check for. Then, we use the `basename` and `dirname` functions to get the name of the current directory where the PHP file is located. We compare this directory name with the specified folder name, and if they match, we output the preload link tag for the blog.php file.

You can include this PHP code in your header file or directly in your HTML file where you want to preload the blog.php file. Make sure to adjust the folder name variable to match the actual folder name where the blog.php file is located.

Rate this post

5 of 5 based on 1303 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us