Jump to content

zhq

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Posts posted by zhq

  1. Hi All,

    when I intend to open a .pdf file in a pop-up window, a blank pop-up window appears and also a 'File download - security warning' window comes out showing: 'unknow file type', save or cancel. I have the hearder - 'Content-Type: application/pdf' in my php code and it works previously. The web server is Xitami and OS is Windows XP. 

    Any help is greatly appreciated.
    Thanks,
    zhq
  2. Hi,

    I got the following error message. I don't know what cause this problem. Please help. Thanks a lot in advance.

    zhq

    ***
    Warning:  file_get_contents(http://localhost/uploadfiles/Process.pdf) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
    in c:\inetpub\wwwroot\vlsi\forward.php on line 18

    Warning:  fopen(http://zhenghq/uploadfiles/Process.pdf) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
    in c:\inetpub\wwwroot\forward.php on line 66

    Warning:  fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\forward.php on line 26

    Warning:  fclose(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\forward.php on line 68
    ***

    the code is here:
    ***
    <?php
    include("download_header.php");
    header("Cache-control: no-cache");

    $filedir = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'] . "/";

    $tempdir = $filedir . "temp/";
    $filedir = $filedir . "uploadfiles/";


    $redirect = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'] . "/";

    $redirect = $redirect . "download_main.php";

    function RemoteFileSize($remote_file)
    {
    echo "<pre>"; var_dump($remote_file); 
    $file = file_get_contents($remote_file);
     
      return strlen($file);
    }

    function Longfread($handle, $size){
    $contents = "";
    do {
      $data = fread($handle, $size);
      if (strlen($data) == 0) {
      break;
      }
      $contents .= $data;
    } while(true);
    return $contents;
    }



    if (isset($_GET['page'])){
    $page=$_GET['page'];

    mysql_connect("localhost","root","") or die ("Unable to connect to MySQL server.");
    $db = mysql_select_db("nus") or die ("Unable to select requested database.");
    $sql = "SELECT f_name from file WHERE f_ID=\"$page\"";
    $result = mysql_query($sql);

    if($result){
    if (mysql_num_rows($result) == 0){
    echo "This file may not exist in database. Please enter your administrator name

    correctly.
    <a href=$redirect>BACK</a>.<br>";
    exit();
    } else{
    $row_array = mysql_fetch_row($result);
    $filename = $row_array[0];
    //$filename ="logout.pdf";
    //$tempdir=$tempdir.$filename;
    echo"<pre>"; var_dump($filename);

    $filedir=$filedir.$filename;
    echo"<pre>"; var_dump($filedir);
    $filesize=RemoteFileSize($filedir);

    //header("Content-Type: application/pdf");
    //header("Content-Length: ".$filesize);
    //header("Content-Disposition: inline; filename=$filename");


    $fp = fopen($filedir, 'rb');
    $pdf_buffer = Longfread($fp, 8192);
    fclose ($fp);
    print $pdf_buffer;
    exit();

    //header("Location: $filedir");
    //exit();

    }
    }

    }else{
    header("Location: $redirect");
    }

  3. Hi,

    I got a ' Parse error: parse error, unexpected T_ELSEIF in c:\inetpub\wwwroot\vlsi\forward.php on line 8' message after I changed the first few lines in order to ensure that dirname($HTTP_SERVER_VARS['PHP_SELF']) is not equal to "/" and "\".

    ***<?php
    include("download_header.php");
    header("Cache-control: no-cache");

    $fd = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'];

    if (dirname($HTTP_SERVER_VARS['PHP_SELF']) == "/")
        {elseif (dirname($HTTP_SERVER_VARS['PHP_SELF']) != "\")
           {$filedir = $fd . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/" ;} else {
            $sub_filedir = dirname($HTTP_SERVER_VARS['PHP_SELF']);
            $sub_filedir = str_replace('\','', $sub_filedir);
            $filedir = $fd . $sub_filedir . "/"; }
         }
    $tempdir = $filedir . "temp/";
    $filedir = $filedir . "uploadfiles/";
            $redirect = $filedir . "download_main.php";

    function RemoteFileSize($remote_file)
    {
       $file = file_get_contents($remote_file);
       
       return strlen($file);
    }

    function Longfread($handle, $size){
    $contents = "";
    do {
       $data = fread($handle, $size);
       if (strlen($data) == 0) {
       break;
       }
       $contents .= $data;
    } while(true);
    return $contents;
    }



    if (isset($_GET['page'])){
    $page=$_GET['page'];

    mysql_connect("localhost","root","") or die ("Unable to connect to MySQL server.");
    $db = mysql_select_db("nus") or die ("Unable to select requested database.");
    $sql = "SELECT f_name from file WHERE f_ID=\"$page\"";
    $result = mysql_query($sql);

    if($result){
    if (mysql_num_rows($result) == 0){
    echo "This file may not exist in database. Please enter your administrator name

    correctly.
    <a href=$redirect>BACK</a>.<br>";
    exit();
    } else{
    $row_array = mysql_fetch_row($result);
    $filename = $row_array[0];
    //$filename ="logout.pdf";
    //$tempdir=$tempdir.$filename;
    $filedir=$filedir.$filename;

    $filesize=RemoteFileSize($filedir);

    header("Content-Type: application/pdf");
    header("Content-Length: ".$filesize);
    header("Content-Disposition: inline; filename=$filename");

    $fp = fopen($filedir, 'rb');
    $pdf_buffer = Longfread($fp, 8192);
    fclose ($fp);
    print $pdf_buffer;
    exit();

    //header("Location: $filedir");
    //exit();

    }
    }

    }else{
    header("Location: $redirect");
    }

  4. In IE address field, something like http://localhost//faqdisplay.php?page=59&type=2. The script is working fine under Xitami Web server. The faqdisplay.php script is below.
    *****
    <?php include("formheader.inc"); ?>
        <td valign="top" height="100%" width="986" style="border-right:none; border-right-width:medium; border-top-style:none; border-top-width:medium; border-bottom-style:none; border-bottom-width:medium; border-left:solid medium #FF6600" bgcolor="#FFFFFF" width="791"><!--mstheme--><font face="Arial, Arial, Helvetica">
       
    <?php

    $filedir = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'];
    if (dirname($HTTP_SERVER_VARS['PHP_SELF']) != "/")
    $filedir = $filedir . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/";
    $filedir = $filedir . "faq/";

    if (isset($_GET['type']) && isset($_GET['page'])){
    $type=$_GET['type'];
    $page=$_GET['page'];
    if($type==1) echo " <font size=\"4\">FAQ: Unix Workstation Related</font><br><br>";
    else if($type==2) echo " <font size=\"4\">FAQ: EDA tools</font><br><br>";
    else if($type==3) echo " <font size=\"4\">FAQ: Design Kits</font><br><br>";
    else if($type==4) echo " <font size=\"4\">FAQ: Others</font><br><br>";
    mysql_connect("localhost","root","") or die ("Unable to connect to MySQL server.");
    $db = mysql_select_db("nus") or die ("Unable to select requested database.");
    $sql = "SELECT * from faq WHERE faq_no=\"$page\"";
    $result = mysql_query($sql);
    if ($result)
    {
    if (mysql_num_rows($result) == 0)
    {
    echo "No FAQ available.<br>";
    exit();
    } else
    {
    $count = mysql_num_rows($result);
    while ($count > 0) {

    $index = 1;
    $row_array = mysql_fetch_row($result);
    //$row_array[2]= strip_tags($row_array[2]);
    //$row_array[2] = StripSlashes($row_array[2]);
    $row_array[2] = ereg_replace("\n","<br>&nbsp&nbsp;", $row_array[2]);
    $row_array[1] = ereg_replace("\n","<br>&nbsp&nbsp;", $row_array[1]);

    echo "<font color=brown><b>Question:</b></font> (ID: ".$row_array[0].")<font color=blue>&nbsp&nbsp".$row_array[1] ."</font><br><br>";
    print "<font color=brown>Answer:</font><br><font color=blue>&nbsp&nbsp".$row_array[2] . "</font><br><br>";
    if ($row_array[3] != "No file attached"){
    echo "File ".$index.": <br><font color=blue>&nbsp&nbsp". $row_array[6]. "&nbsp</font><a href=$filedir".$row_array[3]. ">(View it)</a><br><br>";
    $index++;
    }
    if ($row_array[4] != "No file attached"){
    echo "File ".$index.": <br><font color=blue>&nbsp&nbsp". $row_array[7]. "&nbsp</font><a href=$filedir".$row_array[4]. ">(View it)</a><br><br>";
    $index++;
    }
    if ($row_array[5] != "No file attached"){
    echo "File ".$index.": <br><font color=blue>&nbsp&nbsp". $row_array[8]. "&nbsp</font><a href=$filedir".$row_array[5]. ">(View it)</a><br><br>";
    }
    echo "<hr>";
    $count = $count - 1;
    }

    }
    }
    }

    ?>
       
        <!--mstheme--></font></td>
      </tr>
     
    <?php include("formfooter.inc"); ?>
    ****

    regards
    zhq
  5. Hi all,

    I am using iis 6.0, php 4.4.1 and mysql 4.1.18. I have the problem - the url becomes like http://localhost//... once the page is connected to mysql database. Can anyone tell what the reason could be?

    Any help will be much appreciated.

    zhq
  6. Hi,

    I got the following warning when running php code.

    Warning: session_start(): open(C:\PHP\sessiondata\sess_ea64eb1750d43a0f2c91c74343fd7b25, O_RDWR) failed: Permission denied (13) in c:\inetpub\wwwroot\vlsi\download_action.php on line 95

    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\inetpub\wwwroot\vlsi\download_action.php:95) in c:\inetpub\wwwroot\vlsi\download_action.php on line 95

    Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\vlsi\download_action.php:95) in c:\inetpub\wwwroot\vlsi\download_action.php on line 103

    Warning: Unknown(): open(C:\PHP\sessiondata\sess_ea64eb1750d43a0f2c91c74343fd7b25, O_RDWR) failed: Permission denied (13) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\PHP\sessiondata) in Unknown on line 0

    Any help is much appreciated.

    zhq
  7. Dear All,

    Sorry I am not quite clear about this becasue I am new to all the topic. Using "header('Cache-Control: no-cache')", the downloading to the temp directory can be blockbed. For blocking user to use the 'save as' function to save a PDF file, the java script has to be used. Am I right? Instead of using Java script, can PHP script work for this?

    I need a clear drection so that I know how to start my work. Thanks.

    zhq
  8. Dear All,

     

    The php scripts got errors when running on IIS 6.0 web server and windows server 2003. The error massages and the php codes are shown below. Please help me if you know the answer. Thanks a lot in advance.

     

    zhqnus

     

    ####

    error messages

    ***

    Warning: file_get_contents(): php_network_getaddresses: gethostbyname failed in C:\Inetpub\wwwroot\vlsi\forward.php on line 21

     

    Warning: file_get_contents(http://vlsi-test.ece.nus.edu.sg\/uploadfiles/CMOS_C35_noise_para_ENG-189_rev1.pdf): failed to open stream: No error in C:\Inetpub\wwwroot\vlsi\forward.php on line 21

     

    Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\vlsi\forward.php:21) in C:\Inetpub\wwwroot\vlsi\forward.php on line 62

     

    Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\vlsi\forward.php:21) in C:\Inetpub\wwwroot\vlsi\forward.php on line 63

     

    Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\vlsi\forward.php:21) in C:\Inetpub\wwwroot\vlsi\forward.php on line 64

     

    Warning: fopen(): php_network_getaddresses: gethostbyname failed in C:\Inetpub\wwwroot\vlsi\forward.php on line 66

     

    Warning: fopen(http://vlsi-test.ece.nus.edu.sg\/uploadfiles/CMOS_C35_noise_para_ENG-189_rev1.pdf): failed to open stream: No error in C:\Inetpub\wwwroot\vlsi\forward.php on line 66

     

    Warning: fread(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\vlsi\forward.php on line 29

     

    Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\vlsi\forward.php on line 68

    ####

     

     

    ####

    forward.php

    ***

    <?php

    include("download_header.php");

    header("Cache-control: private");

     

     

    $filedir = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'];

    if (dirname($HTTP_SERVER_VARS['PHP_SELF']) != "/")

    $filedir = $filedir . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/";

     

    $tempdir = $filedir . "temp/";

    $filedir = $filedir . "uploadfiles/";

     

     

    $redirect = "http://" . $HTTP_SERVER_VARS['HTTP_HOST'];

    if (dirname($HTTP_SERVER_VARS['PHP_SELF']) != "/")

    $redirect = $redirect . dirname($HTTP_SERVER_VARS['PHP_SELF']) . "/";

    $redirect = $redirect . "download_main.php";

     

    function RemoteFileSize($remote_file)

    {

    $file = file_get_contents($remote_file);

     

    return strlen($file);

    }

     

    function Longfread($handle, $size){

    $contents = "";

    do {

    $data = fread($handle, $size);

    if (strlen($data) == 0) {

    break;

    }

    $contents .= $data;

    } while(true);

    return $contents;

    }

     

     

     

    if (isset($_GET['page'])){

    $page=$_GET['page'];

     

    mysql_connect("localhost","root","") or die ("Unable to connect to MySQL server.");

    $db = mysql_select_db("nus") or die ("Unable to select requested database.");

    $sql = "SELECT f_name from file WHERE f_ID=\"$page\"";

    $result = mysql_query($sql);

     

    if($result){

    if (mysql_num_rows($result) == 0){

    echo "This file may not exist in database. Please enter your administrator name correctly.

    <a href=$redirect>BACK</a>.<br>";

    exit();

    } else{

    $row_array = mysql_fetch_row($result);

    $filename = $row_array[0];

    //$filename ="logout.pdf";

    //$tempdir=$tempdir.$filename;

    $filedir=$filedir.$filename;

     

    $filesize=RemoteFileSize($filedir);

     

    header("Content-Type: application/pdf");

    header("Content-Length: ".$filesize);

    header("Content-Disposition: inline; filename=$filename");

     

    $fp = fopen($filedir, 'rb');

    $pdf_buffer = Longfread($fp, 8192);

    fclose ($fp);

    print $pdf_buffer;

    exit();

     

    //header("Location: $filedir");

    //exit();

     

    }

    }

     

    }else{

    header("Location: $redirect");

    }

    #####

     

    zhqnus

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.