Php Can';不要把它变成可下载的文件

Php Can';不要把它变成可下载的文件,php,xml,extjs,zip,ziparchive,Php,Xml,Extjs,Zip,Ziparchive,我从服务器下载时遇到问题。如果我输入到无法下载一些.zip文件。但是如果我进入页面的IP,我会下载文件 我遇到的另一个类似问题是Godaddy,即使我使用IP或域访问,也无法进行zip下载 这是生成XML并将其压缩的代码的一部分: **xmlzip.php** $xmlfile = $rfc.$year.$month.'BN.xml'; $xml->formatOutput = true; $el_xml = $xml->saveXML(); $xml

我从服务器下载时遇到问题。如果我输入到无法下载一些.zip文件。但是如果我进入页面的IP,我会下载文件

我遇到的另一个类似问题是Godaddy,即使我使用IP或域访问,也无法进行zip下载

这是生成XML并将其压缩的代码的一部分:

**xmlzip.php**
    $xmlfile = $rfc.$year.$month.'BN.xml';
    $xml->formatOutput = true;
    $el_xml = $xml->saveXML();
    $xml->save($xmlfile);

    $filename = $rfc.$year.$month.'BN';
    shell_exec('zip ../'.$filename.' '.$xmlfile);

    try {
      $date= date('Ymd_Hi');
      $data = '{
          "filename":"xml'.$date.'.zip",
          "filename2":"'.$filename.'.zip"
      }';
      echo '{"success":1,"message":"ok","data":['.$data.']}';
    } catch (Exception $e) {
      $data = '';
      echo '{"error":1,"message":"error","data":['.$data.']}';
      die();
    }
然后,我在ExtJS上获取此信息以创建Messagebox.wait:

**downloadzip button**
     msg = Ext.MessageBox.wait('Generating XML ...', '');
        Ext.Ajax.request({
            url: 'cakephp/app/webroot/xml.php?',
            params:{
                rfc: rfc,
                month: month,
                year: year
            },
            method : "POST",
            headers: {
                'Content-Type': 'application/json'
            },
            jsonData: true,
            timeout: 1000000,
            withCredentials: true,
            success : function(response) {
                var jsonResponse = JSON.parse(response.responseText);
                filename = jsonResponse.data[0].filename;
                filename2 = jsonResponse.data[0].filename2;

                if(jsonResponse.success === 1) {
                    msg.hide();
                    Ext.getCmp("winFormXML_XMLpanel").setHtml(
                        '<iframe id="" name=""'+
                        ' src="cakephp/app/webroot/download_xml.php?filename='+
                        filename+'&filename2='+filename2+'" width="100%" height="100%"></iframe>');
                    Ext.getCmp('winFormXML').destroy();
                } else {
                    msg.hide();
                    Ext.Msg.alert("ERROR","Error generating XML.");
                }

            },
            failure : function(response) {
                msg.hide();
                var respObj = Ext.JSON.decode(response.responseText);
                console.log(respObj);
                Ext.Msg.alert("ERROR", respObj.status.statusMessage);
            }
        });
正如我上面提到的,我知道它是有效的,因为我可以从其他计算机上下载它,但通过IP,而不是从域


编辑:

Ext.getCmp('winFormXML').destroy()在生成时出现问题。移除那条线,让它工作

升级不安全请求:1”表示您的浏览器要求服务器将url(http)转换为安全url(https)

为了实现逻辑的最佳路径,创建一个小cakeph插件(可能是插件),或者只使用一个控制器(如pagesController或专用控制器),并在该控制器内创建一个操作(函数),该操作(函数)将完成您所需的所有工作(对xml文件、zip和下载的操作)

这样,您可以添加一个安全层(例如,仅允许经过身份验证的用户下载您的文件),还可以添加一些统计信息(将下载的计数器保存在数据库中)

我不确定使用shell_exec是否是一种好的做法,相反,请尝试ziparchive 一个有用的例子 还是像这样

<?php

...

$filename2 = 'xml.zip';

$zip = new ZipArchive;

if ($zip->open($filename2, ZipArchive::CREATE)!==TRUE)
{
    die("zip creation failed!");
} else {
    $zip->addFile($xmlfile);
    $zip->close();

    header('Content-Type: application/zip');
    header('Content-disposition: attachment; filename='.$filename2);
    header('Content-Length: ' . filesize($filename2));
    readfile($filename2);
    unlink($filename2);
}
?>

最后,对于您的问题,如果您在使用IP地址时没有升级不安全请求消息,这意味着问题来自您的浏览器。请尝试使用未实现此安全级别的浏览器(如chrome或firefox),或仅将您的网站配置为使用https协议: ->在.htaccess中重定向(在cakephp根目录中)


重新启动发动机
重写cond%{REQUEST_URI}^/(s|g)etcmd?(.+)$
重写cond%{HTTPS}=在…上
重写规则^/?(*)https://%{SERVER_NAME}/$1[R=301,L]
重写cond%{QUERY\u STRING}^(.*)http(\:\\%3A)(.*)$
重写规则。*-[F]
重写规则^$webroot/[L]
重写规则(.*)webroot/$1[L]
->虚拟主机中的一些配置用于在端口443上侦听(如果在*nix下,/etc/apache2/site内部可用)

#使用自动HTTPS重定向,您不应该配置HTTP部分(端口80)
服务器管理员admin@mypage.com
ServerName mypage.com
服务器别名mypage.com
DocumentRoot/var/www/mypage
选项-索引+FollowSymLinks+多视图
允许超越所有
命令允许,拒绝
通融
服务器签名关闭
ErrorLog/var/log/apache2/error.log
服务器管理员admin@mypage.com
ServerName mypage.com
服务器别名mypage.com
DocumentRoot/var/www/mypage
选项-索引+FollowSymLinks+多视图
允许超越所有
命令允许,拒绝
通融
服务器签名关闭
斯伦金安
SSLProtocol all-SSLv2
SSLCipherSuite全部:!ADH:!出口:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
#如果你有安全的证书
SSLCertificateFile/etc/apache2/certificates/YOURCRTFILE.crt
SSLCertificateKeyFile/etc/apache2/certificates/YOURPEMFILE.pem
SSLCertificateChainFile/etc/apache2/certificates/YOURPEMFILE.pem
SSLCACertificatePath/etc/ssl/certs/
SSLCACertificateFile/etc/apache2/certificates/YOURCRTFILE.crt
ErrorLog/var/log/apache2/error.log

希望它有帮助

希望我没有错,但一般来说,如果您在使用IP地址时URL出现问题,则可能是或的问题。请尝试打开命令提示符命令并ping URL mypage.com,如果您在命令结果/输出中没有看到正确的IP地址,请尝试检查DNS或主机文件。另外,不要在cakephp webroot文件夹中启动php脚本,这是一个安全问题/break.upvote,因为您的答案是正确的。谢谢首先,ping到mypage.com及其正确的IP地址。我发现的另一个问题是,当我单击downloadxml按钮时,我的downloadzip.php在两个方面都变为红色(错误/警告),我的意思是当下载在网络选项卡中工作时也是如此。请求标题显示:
升级不安全的请求:1
。没有得到预览或回应。时间在21点暂停了有什么想法吗(.顺便问一下,放置php脚本的最佳路径在哪里?嘿,那里!谢谢你是anwser!我是一个相对新的开发人员,因为时间关系,我使用了php而不是控制器(因为我没有做到这一点).对于ZIP生成,我使用了ziparchive,但尝试了shell_exec来解决我的问题。但是现在我已经解决了这个问题,根据你所说的,我将把它放回取代shell_exec。最后一件事,你能帮我举一个例子,说明如何在cakephp/控制器上创建xml和ZIP吗?cakephp的哪个版本?抱歉,我来了版本2.6.1
<?php

...

$filename2 = 'xml.zip';

$zip = new ZipArchive;

if ($zip->open($filename2, ZipArchive::CREATE)!==TRUE)
{
    die("zip creation failed!");
} else {
    $zip->addFile($xmlfile);
    $zip->close();

    header('Content-Type: application/zip');
    header('Content-disposition: attachment; filename='.$filename2);
    header('Content-Length: ' . filesize($filename2));
    readfile($filename2);
    unlink($filename2);
}
?>
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_URI} !^/(s|g)etcmd?(.+)$
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L] 

    RewriteCond %{QUERY_STRING} ^(.*)http(\:|\%3A)(.*)$
    ReWriteRule .* - [F]    

    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>
# with the automatic HTTPS redirection you are not supposed to configure HTTP part (port 80)
<VirtualHost *:80>
    ServerAdmin admin@mypage.com
    ServerName mypage.com
    ServerAlias mypage.com
    DocumentRoot /var/www/mypage
    <Directory /var/www/mypage/>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order Allow,Deny 
        Allow from All
    </Directory>
    ServerSignature Off
    ErrorLog /var/log/apache2/error.log
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin admin@mypage.com
    ServerName mypage.com
    ServerAlias mypage.com
    DocumentRoot /var/www/mypage
    <Directory /var/www/mypage/>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>
    ServerSignature Off

    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

    # If you have secure certificate
    SSLCertificateFile /etc/apache2/certificats/YOURCRTFILE.crt
    SSLCertificateKeyFile /etc/apache2/certificats/YOURPEMFILE.pem
    SSLCertificateChainFile /etc/apache2/certificats/YOURPEMFILE.pem
    SSLCACertificatePath /etc/ssl/certs/
    SSLCACertificateFile /etc/apache2/certificats/YOURCRTFILE.crt
    ErrorLog /var/log/apache2/error.log
</VirtualHost>