我使用的東西如下面的代碼檢索後,我們作爲輸出使用的PHP電子郵件類的文件的路徑。
//To this folder I'm uploading in another module
$folder='uploads/';
//get the server address.. it's a vpn accessible ip in our case
$dev_baseurl= 'http://192.168.xxx.xyz';
//功能,在這種情況下,*爲我工作(如果有一個更好的方式隨意添加評論)
function check_address($current_dir,$https_check)
{
//$https_check, user defined var for
$conflen=strlen($current_dir);
//im using this and don't ask me why :P
$conflen1=0;
$B=substr(__FILE__,0,strrpos(__FILE__,'/'));
$A=substr($_SERVER['DOCUMENT_ROOT'], strrpos($_SERVER['DOCUMENT_ROOT'], $_SERVER['PHP_SELF']));
$C=substr($B,strlen($A));
$posconf=strlen($C)-$conflen1-1;
$D=substr($C,1,$posconf);
if (isset($_SERVER['HTTPS'])) $https_check=1;
switch($https_check)
{
case 0:
$host='http://'.$_SERVER['SERVER_NAME'].'/' .$D.'';
break;
case 1:
$host='https://'.$_SERVER['SERVER_NAME'].'/'.$D.'';
break;
}
//output the address
return $host;
}
試圖讓遠程託管的文件
路徑
$dev2_url=check_address('/',1);
$dev2_url="{$dev2_url}";
/* That should be the output we are looking for
$dev_url="{$dev_baseurl}".str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']))."/{$folder}";
*/
...在我的PHP一些其他的邏輯
//$body is a message string that we are sending with a class call as a parameter later
foreach($_POST['attachments'] as $a => $avalue)
{
if (is_file($avalue))
{
$mime_type[$a] = substr(strrchr($avalue, '.'), 1);
$handle=fopen($avalue, 'rb');
$bs_name=basename($avalue);
$filesize=filesize($avalue);
$f_contents=fread($handle, $filesize);
fclose($handle);
用於從文件文件類型次
// get_mime_type2檢查,而不是對於本例相關的,但它確實對輸出雖然如果(isset($ MIME_TYPE [$ A]))$ MIME_TYPE [$ A] = get_mime_type2($ MIME_TYPE [ $一]);
$body.= '<li><ul><li>Filename: ' . $bs_name .$eol;
$body.= '<li>FileType: '.$mime_type[$a].$eol;
//In this line I use the calculated path to pass it as an output to an HTML based version of an email
$body.= "<li>Path: <a href=\"{$dev2_url}/{$avalue}\" title=\"Open w/ browser {FileName: $bs_name} | Size: {$filesize}\" target=\"_parent\">" .$avalue . "</a><li>Approx.File-Size:{$filesize} bytes</ul>";
}
}
$body.='</ul>';
所以注意在這行: ...
$body.= "<li>Path: <a href=\"{$dev2_url}/{$avalue}\" title=\"Open w/ browser {FileName: $bs_name} | Size: {$filesize}\" target=\"_parent\">" .$avalue . "</a><li>Approx.File-Size:{$filesize} bytes</ul>";
.. $ dev2_url被用於查找文件的路徑,我們追加文件名,並應照顧它。據我所知,應該有實現的運算需要的東西更優雅的方式,但沒有什麼可以用它真實的情況,因爲我只能分享我自己的實現。
這給了我一個方便的輸出使用.. IE:
//http://192.168.xx.xyZ is actually a real IP address
http://192.168.xx.xyZ/ProjectX/protos/jquery-menu2/includes/uploads/t_1.txt
對於被附加到電子郵件消息
我想你需要'__DIR__'每個文件的輸出。 – Gareth
沒有,返回工作目錄 – Anomaly