Jump to content

willpower

Members
  • Posts

    296
  • Joined

  • Last visited

Posts posted by willpower

  1. Found this...which works...

     

    <?php
    
    function in_object($val, $obj){
    
        if($val == ""){
            trigger_error("in_object expects parameter 1 must not empty", E_USER_WARNING);
            return false;
        }
        if(!is_object($obj)){
            $obj = (object)$obj;
        }
    
        foreach($obj as $key => $value){
            if(!is_object($value) && !is_array($value)){
                if($value == $val){
                    return true;
                }
            }else{
                return in_object($val, $value);
            }
        }
        return false;
    }
    ?>
    Usage  :
    <?php
    
    $array = array("a", "b", "c"=>array("x", "y"=>array("p", "q"=>"r")));
    
    if(in_object("r", $arrX)){
        echo "r is there ";
    }else{
        echo "Its not there ";
    }
    ?>
    

  2. Whats the most efficient way of searching within a multi dimensional array?

     

    My Array =

     

    Array ( [0] => Array ( [0] => Item 1 [title] => Item 1 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) [1] => Array ( [0] => Item 2 [title] => Item 2 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) )

     

    String to find = '21'

     

    If (MY ARRAY contains STRING TO FIND) {}

     

    Clearly in this case there are several '21' (s) so if I only wanted to search the [eventDay] keys...would there be a fast effective and efficient manner?

     

     

    Thoughts and help gratefully received.

     

    Will

  3. Thanks so far...

     

    I need to write a php script to parse the file without ANY manual input.  Ie this sheet will be ftp'd upstream and a cron job will then run the php script...so ALL csv or other processing will take place internally removing the ability to export each sheet separately...unless ofcourse we can establish how to do this in PHP alone.

     

     

  4. Has anyone any experience of parsing worksheet information into separate tables in a DB.  to give an illustration. I have a single workbook, in which there is a worksheet containing data relevant to some staff members...so worksheet 1 - staff member 1 , worksheet 2 - staff member 2 etc.  I need to separate this info into separate DB tables.  Any advice gratefully received.

     

    Thanks

     

    Will

  5. page loads arte slow...and i got bored as there was too much text. layout is good but i felt i was being told to read read read...instead of being aboe to identify key content from you.

     

    layout good , but i still dont know what the site is about as i kinda refused to read read read.

     

    Hope that helps

     

    Will

  6. im with the last comment....you cant say that you design great webiste and put that out there with confidence.

     

    Im not gonna hammer you , but it shows a lack of web understanding and as a result is more likey to deter business than promote it.

     

    Think about this...have you ever seen a print advert look like that...if not...why not?

     

     

    Will

  7. Yesssss.finallly

     

    somone has actually thought about their site before posting it...a nice clean and clear site.  congrats.

     

    couple of points...text is a lil small.  but i guess thats user pref

    site doesnt validate, but i think most of your issues come from the google map link (& not &)

     

    part from that ...good use of simple colour and layout...nice header n footer

     

    and normally im brutal!

     

    Will

  8. Hi

     

    I have some code which opens a directory and reads the contents.  In this case it performs some image manipulationof the jpgs it encounters.

     

    BUT

     

    The problem is that it does this based on the file structure which is by default, alphabetical . I need it to be numeric.

     

    ie

     

    DSC0001.jpg DSC0002.jpg etc

     

    currently i get

     

    DSC0001.jpg  DSC0011.jpg  DSC0002.jpg

     

    etc etc

     

    Any help?????? I am in a real pickle here.

  9. Here is another...both 'force the download'. I need a SAVE AS option....any ideas?

     

    <?php
    function output_file($file, $name, $mime_type='')
    {
    /*
    This function takes a path to a file to output ($file), 
    the filename that the browser will see ($name) and 
    the MIME type of the file ($mime_type, optional).
    
    If you want to do something on download abort/finish,
    register_shutdown_function('function_name');
    */
    if(!is_readable($file)) die('File not found or inaccessible!');
    
    $size = filesize($file);
    $name = rawurldecode($name);
    
    /* Figure out the MIME type (if not specified) */
    $known_mime_types=array(
    	"pdf" => "application/pdf",
    	"txt" => "text/plain",
    	"html" => "text/html",
    	"htm" => "text/html",
    "exe" => "application/octet-stream",
    "zip" => "application/zip",
    "doc" => "application/msword",
    "xls" => "application/vnd.ms-excel",
    "ppt" => "application/vnd.ms-powerpoint",
    "gif" => "image/gif",
    "png" => "image/png",
    "jpeg"=> "image/jpg",
    "jpg" =>  "image/jpg",
    "php" => "text/plain"
    );
    
    if($mime_type==''){
     $file_extension = strtolower(substr(strrchr($file,"."),1));
     if(array_key_exists($file_extension, $known_mime_types)){
    	$mime_type=$known_mime_types[$file_extension];
     } else {
    	$mime_type="application/force-download";
     };
    };
    
    @ob_end_clean(); //turn off output buffering to decrease cpu usage
    
    // required for IE, otherwise Content-Disposition may be ignored
    if(ini_get('zlib.output_compression'))
      ini_set('zlib.output_compression', 'Off');
    
    header('Content-Type: ' . $mime_type);
    header('Content-Disposition: attachment; filename="'.$name.'"');
    header("Content-Transfer-Encoding: binary");
    header('Accept-Ranges: bytes');
    
    /* The three lines below basically make the 
        download non-cacheable */
    header("Cache-control: private");
    header('Pragma: private');
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    
    // multipart-download and download resuming support
    if(isset($_SERVER['HTTP_RANGE']))
    {
    list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
    list($range) = explode(",",$range,2);
    list($range, $range_end) = explode("-", $range);
    $range=intval($range);
    if(!$range_end) {
    	$range_end=$size-1;
    } else {
    	$range_end=intval($range_end);
    }
    
    $new_length = $range_end-$range+1;
    header("HTTP/1.1 206 Partial Content");
    header("Content-Length: $new_length");
    header("Content-Range: bytes $range-$range_end/$size");
    } else {
    $new_length=$size;
    header("Content-Length: ".$size);
    }
    
    /* output the file itself */
    $chunksize = 1*(1024*1024); //you may want to change this
    $bytes_send = 0;
    if ($file = fopen($file, 'r'))
    {
    if(isset($_SERVER['HTTP_RANGE']))
    fseek($file, $range);
    
    while(!feof($file) && 
    	(!connection_aborted()) && 
    	($bytes_send<$new_length)
          )
    {
    	$buffer = fread($file, $chunksize);
    	print($buffer); //echo($buffer); // is also possible
    	flush();
    	$bytes_send += strlen($buffer);
    }
    fclose($file);
    } else die('Error - can not open file.');
    
    die();
    }	
    
    $file='assets/docs/'.$_GET['f'];
    $name=$_GET['f'];
    
    output_file($file, $name, $mime_type='')
    
    
    ?>
    

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