-2

I am writing the system to check available google drive links from users. A user will share the public link from their google drive (Anyone with the link). To make sure that I would link to check every link from users. It can be accessed.

Therefore, I try to use javascript to check their link. This is my example code.

$('#videoCkeck').on('click', function () {
      console.log("check");
      fetch('https://drive.google.com/file/d/1AunwLGuDlprNnM8KBIl7zZLLrYISCGFz/view?usp=sharing')
    .then(response => {
      console.log('response.status: ', response.status); // ️ 200
      console.log(response);
    })
    .catch(err => {
      console.log("error",err);
    });
      
    });

The google link in the above code can be accessed but I got some error when I tried to check it.

error

This is an error that I got it.

Please anyone suggest me? Thank you.

Pisit Nakjai
  • 141
  • 1
  • 1
  • 10
  • I have to apologize for my poor English skill. Unfortunately, I cannot understand `check their link`. Can I ask you about the detail of your goal? – Tanaike Nov 13 '22 at 06:11
  • Sorry about that, I mean check the link that is provided by the user. – Pisit Nakjai Nov 13 '22 at 06:16
  • I found the solution. I write PHP to check the status. I send the URL to my PHP code. This is my solution. // Initialize an URL to the variable // Use get_headers() function $headers = @get_headers($url); // print_r($headers); // Use condition to check the existence of URL if($headers && strpos( $headers[0], '200')) { $status = "URL Exist"; // print_r($headers); } else { $status = "URL Doesn't Exist"; } // Display result echo($status); – Pisit Nakjai Nov 13 '22 at 06:18

1 Answers1

0

I found the solution. I write PHP to check the status. I send the URL to my PHP code. This is my solution.

// Initialize an URL to the variable
// Use get_headers() function
$headers = @get_headers($url);
// print_r($headers);
// Use condition to check the existence of URL
if($headers && strpos( $headers[0], '200')) {
    $status = "URL Exist";
    // print_r($headers);
}
else {
    $status = "URL Doesn't Exist";
}

// Display result
echo($status);
Pisit Nakjai
  • 141
  • 1
  • 1
  • 10