0

I have a CPT that is justed used for linking to resources on a local drive.

I have this code in single-resource.php:

<?php
global $post;
the_post();
$location = get_post_meta($post->ID, 'sc_stace_resource_location', true);
$count = (int) get_post_meta($post->ID, 'sc_stace_view_count', true);
$count++;
update_post_meta($post->ID, 'sc_stace_view_count', $count);
wp_redirect($location);
die();
?>

Basically the user clicks the resource, the resource counter is incremented and then the user should get taken to the file location. An example file location is:

file://S:/_%20Transfer/Scott/wfw_christmas_041111.pdf

Now if I put this in the address bar of any browser the file is loaded fine. but when I navigate with the above code I get a blank page on webkit browsers and a page cannot be displayed in IE browsers.

Not sure if this is a PHP issue or a WordPress issue.

Anyone know why this isn't working?

UPDATE

It appears that the reason why this isn't working is because of security in the browser. The only solution I can think of is to link directly to the file but if I do this I lose the ability to track the number of downloads. Any solutions?

1 Answer 1

0

The above code didn't work because of browser security.

I've decided to go with this code:

<?php
global $post;
the_post();
$location = get_post_meta($post->ID, 'sc_stace_resource_location', true);
$count = (int) get_post_meta($post->ID, 'sc_stace_view_count', true);
$count++;
update_post_meta($post->ID, 'sc_stace_view_count', $count);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php the_title(); ?></title>
<meta http-equiv="REFRESH" content="1;url=<?php echo $location; ?>">
</HEAD>
<BODY>
Redirecting to selected file. If nothing happens <a href="<?php echo $location; ?>">click here</a>
</BODY>
</HTML>

The site I'm developing for is for a company intranet and on their network they have to use IE. Because the site will be an intranet site the site is seen as trusted in IE so file links work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.