Jump to content

Nazwa hostingu wrzuconego url


Go to solution Solved by Weak.,

Recommended Posts

Posted (edited)

Próbuje dodac w dziale download kolumne gdzie bedzie dodawało nazwe hostingu na która został wrzucony plik ale dostaje komunikat "Nieznany hosting" prubuje do tego uzyc ten kod:

 

<span id="hosting-name"></span>
<script>
    const fileUrl = "{file.url}";
    try {
        const url = new URL(fileUrl);
        const host = url.hostname;
        document.getElementById('hosting-name').innerText = host;
    } catch (e) {
        console.error("Nieprawidłowy URL:", fileUrl);
        document.getElementById('hosting-name').innerText = "Nieznany hosting";
    }
</script>

 

Ale nie pobiera nazwy.

 

Drugi sposobem jaki próbowałem to takim kodem:

 

<div class="button buttonPrimary externalURL" style="list-style: none;">
    <p id="hostInfo">Loading host...</p>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const link = document.querySelector('#downloadLink');
        const hostInfo = document.querySelector('#hostInfo');

        if (link) {
            const url = link.href;

            fetch(url, { method: 'HEAD', mode: 'cors' })
                .then(response => {
                    const finalUrl = response.url;
                    const host = new URL(finalUrl).hostname;
                    hostInfo.textContent = Host: ${host};
                })
                .catch(error => {
                    console.error('Błąd w pobieraniu hosta:', error);
                    hostInfo.textContent = 'Nie udało się pobrać hosta.';
                });
        }
    });
</script>

 

 

ale dostaje komunikat "nie udało sie pobrac hosta"

Jak to dobrze zrobić żeby pobierało? Albo jakiś prostszy sposób na to?

Edited by Majster87

logo.png.519590789bae8db2833a4ecc09316aef.png

  • Manager
Posted

A tak?

 

<a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a>

<span id="hosting-name"></span>

<script>
  document.addEventListener('DOMContentLoaded', function () {
    const link = document.getElementById('downloadLink');
    const hostingNameSpan = document.getElementById('hosting-name');

    if (link) {
      try {
        const url = new URL(link.href);
        const host = url.hostname;
        hostingNameSpan.innerText = host;
      } catch (err) {
        console.error('Nieprawidłowy URL:', link.href);
        hostingNameSpan.innerText = 'Nieznany hosting';
      }
    }
  });
</script>

 

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Posted (edited)
Godzinę temu, DawPi napisał(a):

A tak?

 

<a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a>

<span id="hosting-name"></span>

<script>
  document.addEventListener('DOMContentLoaded', function () {
    const link = document.getElementById('downloadLink');
    const hostingNameSpan = document.getElementById('hosting-name');

    if (link) {
      try {
        const url = new URL(link.href);
        const host = url.hostname;
        hostingNameSpan.innerText = host;
      } catch (err) {
        console.error('Nieprawidłowy URL:', link.href);
        hostingNameSpan.innerText = 'Nieznany hosting';
      }
    }
  });
</script>

 

 

Pokazuje adres mojej strony

 

image.png.893827fae9436d1b7950f1947ad78626.png

 

A dodałem to tak:

 

<nav class="contentHeaderNavigation">
                  <div class="button buttonPrimary externalURL" style="list-style: none;">
		<a id="downloadLink" target='_blank' href='{{if settings.idm_antileech AND !$file->requiresDownloadConfirmation()}}{$file->url('download')->csrf()}{{else}}{$file->url('download')}{{endif}}'  {{if $file->requiresDownloadConfirmation()}}data-ipsDialog{{endif}} data-datalayer-postfetch >
			<span id="hosting-name"></span>
<script>
  document.addEventListener('DOMContentLoaded', function () {
    const link = document.getElementById('downloadLink');
    const hostingNameSpan = document.getElementById('hosting-name');

    if (link) {
      try {
        const url = new URL(link.href);
        const host = url.hostname;
        hostingNameSpan.innerText = host;
      } catch (err) {
        console.error('Nieprawidłowy URL:', link.href);
        hostingNameSpan.innerText = 'Nieznany hosting';
      }
    }
  });
</script>							
          <i class="fa-solid fa-download"></i> <span>Download</span> </a>
                      </div>
			</nav>

 

Edited by Majster87

logo.png.519590789bae8db2833a4ecc09316aef.png

  • Manager
Posted
W dniu 8.01.2025 o 10:23, Majster87 napisał(a):

Próbuje dodac w dziale download kolumne gdzie bedzie dodawało nazwe hostingu na która został wrzucony plik ale dostaje komunikat "Nieznany hosting"

No jak jest taki adres:

23 godziny temu, Majster87 napisał(a):
<a id="downloadLink" href="https://mojhosting.pl/pobranyPlik.zip">Pobierz</a>

To jak ma pokazać?

 

Jeszcze raz - co Ty tu kombinujesz? Chodzi o pliki dodane do Downloads?

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

  • Solution
Posted
{{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}}
{{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}}
	{{$parsedUrl = parse_url($url['record_location']);}}
	{{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}}
{{else}}
	{{if $url['record_type'] == 'upload'}}
		{{$host = \IPS\Settings::i()->base_url;}}
	{{else}}
  		{{$host = 'Nieprawidłowy URL';}}
  	{{endif}}
{{endif}}
{expression="htmlspecialchars($host)"}

 

  • Like 1
  • Thanks 1
Posted (edited)
2 godziny temu, Weak. napisał(a):
{{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}}
{{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}}
	{{$parsedUrl = parse_url($url['record_location']);}}
	{{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}}
{{else}}
	{{if $url['record_type'] == 'upload'}}
		{{$host = \IPS\Settings::i()->base_url;}}
	{{else}}
  		{{$host = 'Nieprawidłowy URL';}}
  	{{endif}}
{{endif}}
{expression="htmlspecialchars($host)"}

 

Taki sam komunikat jak ja otrzymuje
image.png.461e5d61be4be7d1f2321f5509fefd6e.png

 

image.png.40193cde7d6c94232dddafa05866eb51.png

Walcze juz z tym 3 dni i cały czas albo Nieprawidłowy URL, albo puste pole albo Error 😕

Edited by Majster87

logo.png.519590789bae8db2833a4ecc09316aef.png

Posted
3 godziny temu, Weak. napisał(a):
{{$url = \IPS\Db::i()->select('record_location, record_type', 'downloads_files_records', [ 'record_file_id = ?', $file->id ])->first();}}
{{if $url['record_type'] == 'link' AND filter_var($url['record_location'], FILTER_VALIDATE_URL)}}
	{{$parsedUrl = parse_url($url['record_location']);}}
	{{$host = $parsedUrl['host'] ?? 'Nieznany hosting';}}
{{else}}
	{{if $url['record_type'] == 'upload'}}
		{{$host = \IPS\Settings::i()->base_url;}}
	{{else}}
  		{{$host = 'Nieprawidłowy URL';}}
  	{{endif}}
{{endif}}
{expression="htmlspecialchars($host)"}

 

 

Wkleiłem jeszcze raz i zadziałało 😛

Dzięki

logo.png.519590789bae8db2833a4ecc09316aef.png

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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.