Jump to content

CMK08

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Posts posted by CMK08

  1. Hello there,

     

    Last night I worked on this script on my mac os x and everything was working beautifully. This morning I came to work to test the same script on a windows machine - apache 2.2.8, php 5.2.6, mysql 5.0.51b - and now I get this warning:

     

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\downloads\zipplet.php on line 19

     

    Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\downloads\zipplet.php on line 27

     

    Here is the code:

     

    <?PHP
    require_once('../connect.php');
    //initiates the array to build form
    
    $fileList2 = array();
    
    //this is a place holder for data coming from log in
    
    $user_id=2;
    
    //select query to display only data belonging to current user
    
    $qry = "Select user_name, rpt_name  FROM data_reports_users where user_id=$user_id";
    
    $r = mysqli_query($dbc,$qry);
    
    //retrieve data from query result and put it in $fileList2
    
    while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
    
    $fileList2[] = $row['rpt_name'];
    
    	  		  
    }
    
    
    mysqli_free_result($r);
    
    mysqli_close($dbc);
    

     

    Any ideas?

     

    Thanks!

  2. Orio, you were right. I don't know why the script didn't work the first time I tried with the edits you made. After trying several different things, I ended up moving the form tags to the end (like you did) and now it works. The only difference between your edits and mine are the escaped quotes. I must have missed something when using your solution. Thank you very much!

  3. I tested just this piece of the code:

    <?php
    $zipFile = 'reports.zip';
    header('Pragma: public');
    header('Cache-Control: must-revalidate, post-check=0');
    header('Content-type: application/download');
    header('Content-type: application/zip');
    header('Content-Type: application/force-download');
    header('Content-Disposition: attachment; filename='.basename($zipFile).';');
    header('Content-Transfer-Encoding: binary');
    //header('Content-Length: '.filesize($zipFile).';');
    @read($zipFile);
    ?>

     

    While the zip folder does have files in it, the folder downloaded with this script is empty. I think I am missing something in this code.

  4. It looks like a logical error on my form...

    <?php
    //this array is built with query result
    
    $fileList2= array('1'=>'contact.html','2'=>'index.php','3'=>'re.txt','4'=>'korean_test.pdf');
    
    echo '<form action=zip.php method=post>';
    
    foreach ($fileList2 as $value=>$name){
    
    echo "<p><input type=\"checkbox\" name= $value >$name</p>";
    
    }
    echo "<input type=submit name=submit value=Download></form>";
    
    // after form is submitted: 
    
    if(isset($_POST['submit'])){  
    
    //prepare list of items to zip
    
    $fileList = array();
    
    foreach($fileList2 as $value=>$name){
    
    if(isset($_POST[$value])){
    
    	$fileList[]= $name;
    
    }
    }
    
    //if at least one item was selected zip them up and send it to the browser
    
      if (!empty($fileList)){
    
    // create object
    	$zip = new ZipArchive();
    
    	// open archive 
     	if ($zip->open('reports.zip', ZIPARCHIVE::CREATE) !== TRUE) {
       	 		 die ("Could not open archive");
    	}
    
    	$numFiles = $zip->numFiles;
    	if($numFiles>0){
    	  for ($x = 0; $x<$numFiles;$x++){
    
    		$file = $zip->statIndex($x);
    
    		$zip->deleteIndex($x) or die("ERROR: Could not delete file");
        
    }	
    
    }
    
    $item = $fileList[0];
    echo $item.'<br>';
    
    // add files
     foreach ($fileList as $f) {
        $zip->addFile($f) or die ("ERROR: Could not add file: $f");   
    	}
        
    // close and save archive
    $zip->close();
    $filename='reports.zip';
    //header('Location: reports.zip'); 
    header('Pragma: public');
    header('Cache-Control: must-revalidate, post-check=0');
    header('Content-type: application/download');
    header('Content-type: application/zip');
    header('Content-Type: application/force-download');
    header('Content-Disposition: attachment; filename='.basename('reports.zip').';');
    header('Content-Transfer-Encoding: binary');
    //header('Content-Length: '.filesize('reports.zip').';');
    @read('reports.zip');
    exit;
    
    } Else{ echo "you must select an item";}}
    else {
    
    echo "Please select the reports you would like to download";}
    
    ?>

     

    The message that should appear after the file has been created is ending up in the zip file that is downloaded. It is as if the zip folder is being downloaded before the files get in it. I checked this folder (which is in the same directory as the scripts) and the correct files are in it.

  5. I moved that script back to my form, tried the download, and it looks like it is downloading the code instead of "reports.zip"... I did this locally, and this is what I got in the zip folder:

     

    <form action=zip.php method=post><p><input type="checkbox" name= 1 >contact.html</p><p><input type="checkbox" name= 2 >index.php</p>
    <p><input type="checkbox" name= 3 >re.txt</p><p><input type="checkbox" name= 4 >korean_test.pdf</p>
    <input type=submit name=submit value=Download></form>index.php<br>Archive created successfully.

     

    That would explain why the zip files from the website were blank after I removed the filesize line. Even though I am specifying a file to be downloaded, the code is trying to download the html page.

     

     

    test.php is supposed to handle the zip.php form:

    <?php
    $zipFile = 'reports.zip';
    header('Pragma: public');
    header('Cache-Control: must-revalidate, post-check=0');
    header('Content-type: application/download');
    header('Content-type: application/zip');
    header('Content-Type: application/force-download');
    header('Content-Disposition: attachment; filename='.basename($zipFile).';');
    header('Content-Transfer-Encoding: binary');
    //header('Content-Length: '.filesize($zipFile).';');
    @read($zipFile);
    ?>
    

     

  6. I am having trouble using this code I found on a different thread. If I force the download by redirecting the user with header(Location: file.zip) all works well, except that instead of getting a "download" dialog, the user gets a "now opening" dialog.

     

    With the code below, I get the "downloading" dialog, but the file gets corrupted. Can anyone spot the problem?

     

    thanks

     

    <?php 
    
    
    // My Zip file to Download
    $zipfile = "myZip.zip";
    
    header("Pragma: public");
    
    // set expiration time
    header("Expires: 0"); 
    
    // browser must download file from server instead of cache
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
    // force download dialog
    header("Content-Type: application/force-download");
    header("Content-Type: application/zip");
    header("Content-Type: application/download");
    
    
    // Display the save dialog to the user with the filename
    header("Content-Disposition: attachment; filename=".basename($zipfile).";");
    
    
    // Shows a progress bar for the downloading file
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($zipfile));
    
    @readfile($zipfile);
    ?>

  7. Off the top of my head, it sounds like you will have to create an array or arrays to get that to happen.

    I am not sure about the syntax, but I did something similar once when I needed to create a list of cities in a given country.

     

    I created the content array first - example: $us = array ('1'=>'Los Angeles', '2'=>'New York'...)

    $brasil=array('1'=>'Sao Paulo', '2'=>'Rio de Janeiro'...)

     

    and finally $country = array($us, $brasil)

     

    Then you will have to create a foreach loop inside another foreach loop in order to display things as you described...

     

    foreach (country array){

     

    title of the table goes here

        foreach (city array){

     

        table syntax goes here

    }

     

    }

     

    This should get you started. Hope this helps

  8. Hello there

     

    I am quite new to php and I am working on an application that will let users download several files at once. Basically, the user logs in, then they will see a list of the files available for them - it can be anything between 1 and 300 - they can check the ones that they want to download,  they click the download button, a zip file containing the selected files is created and sent to the browser.

     

    I have doubts about how many people can be doing this at the same time. I don't have any exotic functions in my script. Simply a couple of arrays, the zip file is sent to the browser via header('Location: file.zip'). Right now I am just testing this part of the script, but I am really concerned that I will have problems for doing it this way once I start getting hundreds of clicks at the same time.

     

    Thanks!

     

    CMK08

×
×
  • 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.