Jump to content

Renaming a linked file


Johann
 Share

Recommended Posts

Dear W3School-supporter and friends, Frist of all a heartily "Hello everyone" and a great thanks for making such resoures like here avaliable and keep it easy accessable alive. Also much acclamation for all the documentations on this sites. They are really useful and are even able to teach and support such a internet and programming dummy like me.Much Gratitude! sadhu_sangham_sw.gif I hope its the right way and the right place to raise a particular question. I would like to "generate" links and the path should include a modified file name. So for example:There is a file on a path: http://website/html/named test.html resultion a url: http://website/html/test.html An I would like to "automatical" create a link in this "test.html" that refers to the same path of the file but with modified name. Like for example: test_en.html So in the file should appear a link to http://website/html/test_en.html I had found some scripts to display the path and file when calling for the file, put no simple solution in generating it further.Does anybody know a simple and "easy" way without the need of many programming skills?Thanks in advance and sorry if the question is placed on the wrong place in the forum or very naively. sadhu_sangham_sw.gif

Link to comment
Share on other sites

I would use PHP to grab the document root, then perform some string functions to separate the filename and append the new string. Then you could use something like file_put_contents() to add the link to the file. Kind regards, Lab.

Link to comment
Share on other sites

Thanks a lot for your advice, Lab theoretical I also would think is such a direction, practical I am really not into php and thought of php might be not supported from the host, it would cause additional cost (direct or indirect, nothing is for free). So if you have a hint or trick to get around such a problem, it would be great. Thought of a big content of pages, maybe such is even handle able with a editor trick with a special "replace" function and to make it on the offline side (not "automatically"). Thanks anyway for your care and hint, Lab.sadhu_sangham_sw.gif

Link to comment
Share on other sites

Thanks a lot for your advice, Lab theoretical I also would think is such a direction, practical I am really not into php and thought of php might be not supported from the host, it would cause additional cost (direct or indirect, nothing is for free). So if you have a hint or trick to get around such a problem, it would be great. Thought of a big content of pages, maybe such is even handle able with a editor trick with a special "replace" function and to make it on the offline side (not "automatically"). Thanks anyway for your care and hint, Lab. sadhu_sangham_sw.gif
Use a different free web host?I recommend fav.cc they have PHP installed on free web hosting.
Link to comment
Share on other sites

Thanks a lot for your hint MarkT, sure, there are always ways around and currently I don't miss it. It was rather to keep the topic useful for others as well and not only for solving only my "problem". As told, things even they are mentioned as free, are not free. The costs one has to pay back indirectly any way. So that is why I try to get around all additional software even if they could be included in this or that host package.So I try to keep it on the HTML level which is the most used source and simplest on internet I guess.Machines need fuel anyway and not seeing that directly does not mean that such is not used. Its like if you need to cut a little bit of wood and take the high-tech saw and not just use the hand saw next to one.How ever, I am very happy about your care and generous hint.sadhu_sangham_sw.gif

Link to comment
Share on other sites

Without using server language such as PHP, you are limited to javascript/jquery but this has its drawbacks, javascript MUST be enabled on the users browsers to function, also by using javascript the changed links won't be pickup through search engine only the default link .test.html will be found.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script><script type="text/javascript">/*<![CDATA[*//*---->*/var lang = "en";$(function(){$('a').each(function(){var Current_Link = $(this).attr('href');$(this).attr('href', Current_Link.replace('.html', '_'+lang+'.html'));})});/*--*//*]]>*/</script>

<a href="test1.html">link1</a><a href="test2.html">link2</a><a href="test3.html">link3</a><a href="test4.html">link4</a><a href="test5.html">link5</a>

  • Like 1
Link to comment
Share on other sites

Thanks a lot for your hint MarkT, sure, there are always ways around and currently I don't miss it. It was rather to keep the topic useful for others as well and not only for solving only my "problem". As told, things even they are mentioned as free, are not free. The costs one has to pay back indirectly any way. So that is why I try to get around all additional software even if they could be included in this or that host package.So I try to keep it on the HTML level which is the most used source and simplest on internet I guess.Machines need fuel anyway and not seeing that directly does not mean that such is not used. Its like if you need to cut a little bit of wood and take the high-tech saw and not just use the hand saw next to one. How ever, I am very happy about your care and generous hint. sadhu_sangham_sw.gif
I don't really understand what you are saying,Fav.CC is Totally Free & Unlimited, the only thing they do is put a small advert on the bottom of your site.Everything else comes FREE. Unlimited Bandwidth/Storage/Db's/Email addresses etc
Link to comment
Share on other sites

Without using server language such as PHP, you are limited to javascript/jquery but this has its drawbacks, javascript MUST be enabled on the users browsers to function, also by using javascript the changed links won't be pickup through search engine only the default link .test.html will be found.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script><script type="text/javascript">/*<![CDATA[*//*---->*/ var lang = "en"; $(function(){ $('a').each(function(){ var Current_Link = $(this).attr('href'); $(this).attr('href', Current_Link.replace('.html', '_'+lang+'.html')); }) });  /*--*//*]]>*/</script>

<a href="test1.html">link1</a><a href="test2.html">link2</a><a href="test3.html">link3</a><a href="test4.html">link4</a><a href="test5.html">link5</a>

Wohh! Thanks for the share dsonesuk, Technical it seem to be exactly what I searched for, but as you have told, it requires the installation of javascript/jquery and I guess many would even block such. I guess it would also cause additional traffic on this http://ajax.googleapis.com/ server. Nevertheless, thanks a lot and I will try how it works and try to understand it.Not sure where and how to put to refer to specific single links in one file. I guess the best way will be to make it manual, 70% I have done already of the 5000 pages what does not mean that it is a lost gift, sure that I will try develop it further.Thanks a lot, dsonesuk!
Link to comment
Share on other sites

Use a different free web host?I recommend fav.cc they have PHP installed on free web hosting.
Dear MarkT, nothing is for free and comes form nothing, even the normal consumer is blinded by such and expands his obligations. One has to give things with strings back, direct, indirect, consciously, unconsciously... Be careful! Even it is very complex one is sure have no demands by going the maybe more difficult seeming way. One is always faster by foot as by car. Its just that we usually think that somebody else will pay our personal bills. That is a little speculative and might a heavy burden later on.But as told, thanks for your hint. I really appreciate your good will! sadhu_sangham_sw.gif
Link to comment
Share on other sites

I use http://www.0fees.net and I can do everything I need to with PHP and DB's. I might have a look at Fav.CC but I don't like the sound of them adding their advert to your site. Regards, Lab.
For sure a solution Labtec, we have got or host possibility from a not only generous but also thoughtful donor and are able to use a hosting on an eco-server (https://ssl.greensta.de/). Actually it provides nearly everything and the package is about 40€ a year so it is real fair and out of this we really dont like to overuse all this as well it would be nonsense to host on an eco-server and cause here and there indirect trouble by using many external resources which are not so secure and thoughtful. Not to speak about adds... Freedom of remorse is really something very heart lightening and excuses do not help to get around, just the opposite, one would think and speculate... endless. Thanks a lot for the hint anyway! Maybe you hint with an internal php - solution would be possible and at least the "best" way behind doing it by hand, but I guess I have to less understanding for that stuff. sadhu_sangham_sw.gif Edited by Johann
Link to comment
Share on other sites

JavaScript is read and run through all browsers without any installation, but you do have the option to disable it. additional traffic from http://ajax.googleapis.com can be fixed by downloading the Jquery lib files directly to your server. Edit: you can target specific link by targetting a class given ti the link itself, or parent container it is within

<a class="langlink" href="test1.html">link1</a><a class="langlink" html">link2</a><a class="langlink" html">link3</a><a class="langlink" href="test4.html">link4</a><a class="langlink" href="test5.html">link5</a>

$('.langlink').each(function()....

<div class="langwrap"><a href="test1.html">link1</a> <a html">link2</a></div><p> some text </p><div class="langwrap"><a html">link3</a> <a href="test4.html">link4</a> <a href="test5.html">link5</a></div>

$('.langwrap a').each(function()...

Edited by dsonesuk
Link to comment
Share on other sites

Thanks a lot Ddonesuk! Sorry for the late replay, I need a little to be used to the forum functions here and so a had overseen your replay. More than useful! I will test it and try to fully understand and use it if I am smart enough to get through it function fully. Also the hint on installing the Jquery lib files direct on the server, although I do not understand the process fully for now. Does that mean that every visitor calls up the file instead from a third server from "my" server? (of course that issue is a little off-topic) And I guess I have to change the head of the HTML file as well to give the new address on the "own" server (host), is this right?Just tried to look follow the link ajax.googleapis.com and got:"404. That’s an error.The requested URL / was not found on this server. That’s all we know."Strange... Many thanks for all the hint and support! sadhu_sangham_sw.gif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...