Hi,
I have problem downloading files from a sharepoint driven page. I have tried many tutorials and tips on the net but they doesn't sem to work.
It works if I make a Link to the file but does not work using fileopen and such metods.
I hope that someone is able to help me.🙂
[Added PHP tags around code -- MOD]
<?php
//*******************************************************************************
//Einar Selnes 2010. *
//Trekkut hyperlinker fra en fil og forandre relative linker til absolute. *
//Er beregnet på powerpoint filer fra IMS-TOOLS *
//*******************************************************************************
$myFile = "imstools.txt";
$fileOpen = fopen($myFile, 'r');
$Data = fread($fileOpen, filesize($myFile));
$DataToArray = explode('<',$Data);
fclose($fileOpen);
//Settinn < i starten for alle verdiene i arrayen
$sizeA = count($DataToArray);
$i=0;
while ($i<$sizeA){
$DataToArray[$i] = "<".$DataToArray[$i];
$i++;
}
//trekkut alle linker
$sizeA = count($DataToArray);
$DataLink = array();
$i=0;
$j=0;
while ($i<$sizeA){
//forst sjekk for linker
if(substr($DataToArray[$i], 0, 2) == "<A" or substr($DataToArray[$i], 0, 2) == "<a" or substr($DataToArray[$i], 0, 3) == "< A" or substr($DataToArray[$i], 0, 3) == "< a"){
//sjekk for linker med inneholde HREF="javascript:"
if(strpos($DataToArray[$i], 'HREF="javascript:"') != TRUE){
if(strpos($DataToArray[$i], 'TABINDEX') != TRUE){
if(strpos($DataToArray[$i], '.doc"') == TRUE){
$DataLink[$j] = $DataToArray[$i];
$j++;
}
}
}
}
$i++;
}
//unik sjekk
$result = array_unique($DataLink);
//echo $result;
//linker fra relative til absolut
$insert_string = 'http://intra.tull.net';
$position = 32;
$sizeA = count($DataLink);
$i = 0;
while ($i<$sizeA){
$newstring = substr_replace($DataLink[$i], $insert_string, $position, 0);
$DataLink[$i] = $newstring;
$DataLink[$i] = substr($DataLink[$i], 32);
$DataLink[$i] = strstr($DataLink[$i], '" onclick="', true);
$i++;
}
$minFil = "testFil.txt";
$fh = fopen($minFil, 'w') or die("Kan ikke åpne filen");
$i = 0;
while ($i<$sizeA){
$stringData = $DataLink[$i];
fwrite($fh, $stringData."\n");
//echo $stringData;
$i++;
}
fclose($fh);
$i = 0;
while ($i<$sizeA){
echo '<a href="'.$DataLink[$i].'">'.$DataLink[$i].'</a>'."\n";
$i++;
}
//WINDOWS AUTHENTICATION
if(empty($_SERVER['PHP_AUTH_USER']) ||
empty($_SERVER['PHP_AUTH_PW']) ) {
header('WWW-Authenticate: Basic realm="domain_name"');
header('HTTP/1.0 401 Unauthorized');
die(); //if they hit cancel
}
//Husk å kode i UTF8
?>