English 中文(简体)
PHP服务器提出申请
原标题:PHP server to server file request
  • 时间:2011-06-20 22:35:08
  •  标签:
  • php

I have script-1 on server A, where user ask for a file.
I have script-2 on server B (the file repository) where I check that user can access it and return the correct file (I m using Smart File Download http://www.zubrag.com/scripts/download.php).

I ve Trial cURL and file_get_contents, I ve以各种方式改变了内容标题,但In t仍然能够下载档案。

这是我的要求:

$request = "http://mysite.com/download.php?f=test.pdf";

and it works fine. What should I call in script-1 to force the file be downloaded?

www.un.org/Depts/DGACM/index_spanish.htm 我的一些著作:

这项工作,但我不知道如何处理未经许可或中断的下载。

header( Content-type: application/pdf );

$handle = fopen($request, "r");

if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}

这在浏览器(我认为它是一个头重问题)中直接打印了《pdf法》(而不是文本):

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $request);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
    else return FALSE;

这产生了一个白页。

file_get_contents($request);
最佳回答

<><>>

最后,我简单地将请求改写如下:

header("Location: $request");
问题回答

增 编

 header( Content-disposition: attachment );

但请注意,它不再出现在吉大港山区1.1 光谱中,见。 1. 在“吉大港山区行动计划”回复中采用内容处理标题

如果没有你的密码,我不知道你是如何尝试的,但你需要通过URL获得档案内容,然后将其留给服务器。 ......

$url =  http://website.com/file.pdf ;
$path =  /tmp/file.pdf ;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$contents = curl_exec($ch);
curl_close($ch);

file_put_contents($path, $contents);

如果你想要从FTP服务器下载文件,那么你可以使用《加拿大档案传输协议》的延伸。 请参看以下法典:

<?php
$SERVER_ADDRESS="";
$SERVER_USERNAME="";
$SERVER_PASSWORD="";
$conn_id = ftp_connect($SERVER_ADDRESS);

// login with username and password
$login_result = ftp_login($conn_id, $SERVER_USERNAME, $SERVER_PASSWORD);

$server_file="test.pdf" //FTP server file path 
$local_file = "new.pdf"; //Local server file path 

##----- DOWNLOAD $SERVER_FILE AND SAVE IT TO $LOCAL_FILE--------##
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file
";
} else {
    echo "There was a problem
";
}

ftp_close($conn_id);
?>

http://php.net/Function.readfile"rel=“nofollow”

它显示了如何下载。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签