Welcome Guest, Not a member yet? Register   Sign In
  Safari/quicktime not recognising mp3s piped through CI
Posted by: El Forum - 01-23-2008, 04:33 AM - No Replies

[eluser]pwninja[/eluser]

Code:
function do_download()
    {
        ob_end_clean();
        if(file_exists($this->fpath) && $fh = fopen($this->fpath, "rb")){
            $bufsize = 20000;            
            header("Accept-Ranges: bytes");
            header("Content-Length: ".filesize($this->fpath));
            header("Content-Type: ".$this->mimetypes[pathinfo($this->fpath,PATHINFO_EXTENSION)]); // "audio/mpeg"
            while($buf = fread($fh, $bufsize))
            {
                echo $buf;
            }    
            fclose($fh);
            
            $this->load->model('File_model');
            $this->File_model->increment_downloads($this->uri->segment(2), $this->uri->segment(3));
        }
        else
        {
           header("HTTP/1.0 404 Not Found");
           show_404($this->uri->segment(3));
           exit();
        }
    }

I'm using the above to pipe files through PHP/CI and it works fine on all browsers bar Safari. It only causes problems with media files such as mp3s and avis, the quicktime plugin in Safari tries to take over the handling of the file and ends up giving an error (the annoyingly un-verbose question mark over a quicktime logo). I've tried the exact same code minus the CI specific stuff in raw PHP and it works fine, I've also tried cleaning the output buffer directly before and compared the returned headers, which were identical.


  When it comes to echoing or setting do you prefer ' or "
Posted by: El Forum - 01-23-2008, 03:57 AM - Replies (13)

[eluser]Lone[/eluser]
As most of us on here are advanced php developers Im really curious to know what preferred way of echoing/setting variables/text people have. Do you prefer to use a single quote or double quote or a mixture of the two - and why?


Situation 1 - Echoing html/text

Personally, I use a mixture of the two when it comes to outputting html such as a repetitive table row eg.

Code:
function output_row($title,$value) {
  echo "<tr>\n";
  echo "\t".'<td class="title">'.$title.'</td>'."\n";
  echo "\t".'<td>'.$value.'</td>'."\n";
  echo "</tr>\n";
}

Sure its a lil bit more code, but if I use " then I have to use \ for setting tag variables like class and when there is a few it makes it hard to read. I hate unformatted html as well hence the \n and \t

The other alternative (which I use sometimes but fear the {} for some reason) I have seen is below:

Code:
function output_row($title,$value) {
  echo "<tr>\n";
  echo "\t<td class=\"title\">($title)</td>\n";
  echo "\t<td>{$value}</td>\n";
  echo "</tr>\n";
}
EDIT: () is meant to be {}


Situation 2 - Setting variables

I get into the habit now of setting variables using single quotes every now and again - but uncertain if there is a downside to this compared to "?

Code:
$text = 'some text';


As I said im more curious just to see what habits other people have formed and if there is any performance/memory/convention advantages or using one over the other?


  XSS filtering and HTML
Posted by: El Forum - 01-23-2008, 03:53 AM - Replies (8)

[eluser]Ahmed Nuaman[/eluser]
Hi,

I kept getting the error:

Code:
<br />

<b>Fatal error</b>:  Call to undefined function get_instance() in <b>D:\XXXX\wwwroot

\system\libraries\Input.php</b> on line <b>855</b><br />

PHP Fatal error:  Call to undefined function get_instance() in D:\XXXX\wwwroot\system

\libraries\Input.php on line 855

I fixed it by:

Code:
function _html_entity_decode_callback($match)
    {
        /*$CI =& get_instance();
        $charset = $CI->config->item('charset');*/
        
        $CFG =& load_class('Config');
        $charset = $CFG->item('charset');

        return $this->_html_entity_decode($match[0], strtoupper($charset));
    }

I hope that's cool.


  Passing DOM in XMLHttpRequest
Posted by: El Forum - 01-23-2008, 03:13 AM - Replies (8)

[eluser]Xiphar[/eluser]
Hi
Do you know how can I pass a DOM object to my XMLHttpRequest, receive it at the php side, parse it to do some stuff, and return a simple confirmation?

I've been googling for a whole day now but there is nothing that helps.. The XMLHttpRequest specs say dom object can be passed.. I donno how.. to send and handle it at the php side..

Please Help

Xiphar


  Files outside webroot directory ? or other method for protecting images from direct access
Posted by: El Forum - 01-23-2008, 01:10 AM - No Replies

[eluser]Unknown[/eluser]
Hello All,
Is it possible to keep uploaded files above webroot directory ? I know that it possible to keep application files above, but I want to keep uploaded files (including uploaded images) too ?

If so , could you give me an example how to retrieve them from this directory ?

If not, what are the other methods of protecting images/files from direct accessing ?


Regards
bastek


  insert data into database
Posted by: El Forum - 01-23-2008, 01:02 AM - Replies (4)

[eluser]Sawariya[/eluser]
hai friends

i have three sites .. i want to insert data in to all three database at a time.. how its possible...
anybody have idea about this..

thanks...


  [SOLVED] What should be my main .htaccess to access both CI and non-CI apps?
Posted by: El Forum - 01-23-2008, 01:00 AM - Replies (2)

[eluser]daBayrus[/eluser]
Heres my webroot structure:

/
.htaccess
CI-app1/
CI-app2/
CodeIgniter (this is CI's system folder)
index.php
non-CI-app1/
non-CI-app2/

here's the current .htaccess

Code:
Options +SymLinksIfOwnerMatch
    
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(non-CI-app1|non-CI-app2)
    RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>

I'am able to access both CI and non-CI apps but the images and CSS styles are not loaded for the non-CI apps. If I removed the .htaccess file, non-CI apps load just fine, which obviously means, I have no access for the CI apps.

Any ideas? Many thanks in advance...


  Mini Textile Library - Updated
Posted by: El Forum - 01-23-2008, 12:59 AM - Replies (10)

[eluser]Lone[/eluser]
If you are not familiar with what textile is please click here. I love using Textile for the output of textarea boxes on any websites that we do as it is a simple markup language that still makes some sense unformatted.


TextilePHP and CI
I actually started off usi_ng the TextilePHP class with instructions for implementation in CI from the CI Wiki. But one offsetting thing for me was the sheer size of the class and the fact that it add another 1.2mb to memory usuage in CI.


Let's minimify!
I have come to the realisation that there are four main features of Textile that I only use so decided to make a small helper file that just carried on these main features that I used it for.


So what can it do?
You send the helper function a string that has been written using the textile style and it will return the HTML for output. Currently it will interpret only the following textile formats:

- Paragraphs (&lt;p&gtWink
- Line breaks (&lt;br /&gtWink
- Strong/bold (&lt;strong&gtWink
- Emphasis (&lt;em&gtWink


So how do I use it?
First of all save the following code snippet to your application/libraries dir as 'Minitextile.php'

Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Minitextile {

    // Generates <em> tags
    function em($text) {
        return preg_replace('/\_([^\*]+)\_/','<em>$1</em>',$text);
    }

    // Generates <strong> tags
    function strong($text) {
        return preg_replace('/\*([^\*]+)\*/','<strong>$1</strong>',$text);
    }
    
    // Generates <br /> tags
    function br($text) {
        return preg_replace('/(.+)\n(.+)/m','$1<br />$2', $text);
    }
    
    // Generates paragraphs - note: needs to have linebreaks fixed first
    function paragraph($text) {
        $text = $this->fix_linebreaks($text);
        $paragraphs = explode("\n\n", $text);
        $output = '';
        foreach($paragraphs as $paragraph) {
            $output .= "\n<p>".$paragraph."</p>\n";
        }
        return $output;
    }
    
    /**
     * Fixes linebreaks that can be entered into a textarea from different systems - used for paragraph
     * windows = \r\n
     * unix = \n
     * mac = \r
     */    
    function fix_linebreaks($text) {
        return str_replace(array("\r\n", "\r", "\n"), "\n", $text);
    }
    
    function process($text) {
        $text = $this->em($text);
        $text = $this->strong($text);
        $text = $this->paragraph($text);
        $text = $this->br($text);
        return $text;
    }
    
    function strip($text) {
        $text = $this->process($text);
        $text = strip_tags($text);
        return $text;
    }

}
?&gt;

Now you need to load the library, you can either autoload it to your autoload.php (recommended) or just use:
Code:
$this->load->library('Minitextile');

To use the function it is as easy as:
Code:
echo $this->Minitextile->process($string);


I plan to extend this down the track but it serves its purpose for now and Im certain it will be handy for some people on here.

Also, if you find any bugs please let me know in here!


  Validation Rules and non-primitive Form Fields
Posted by: El Forum - 01-22-2008, 11:50 PM - No Replies

[eluser]Unknown[/eluser]
I am developing this application where there will a handful fields on the form that needs to be dynamically generated, some thing like these:
...
URL 1 Text: &lt;input type="text" name="data[url][text][]"&gt;
URL 1 Link: &lt;input type="text" name="data[url][link][]"&gt;

URL 2 Text: &lt;input type="text" name="data[url][text][]"&gt;
URL 2 Link: &lt;input type="text" name="data[url][link][]"&gt;

URL 3 Text: &lt;input type="text" name="data[url][text][]"&gt;
URL 3 Link: &lt;input type="text" name="data[url][link][]"&gt;

URL 4 Text: &lt;input type="text" name="data[url][text][]"&gt;
URL 4 Link: &lt;input type="text" name="data[url][link][]"&gt;

URL 5 Text: &lt;input type="text" name="data[url][text][]"&gt;
URL 5 Link: &lt;input type="text" name="data[url][link][]"&gt;
...

Those are dynamically generated DOM elements by Javascript as the number of URL links are indefinite. However, it doesn't see that CodeIgniter is capable of handling non-primitive type fields, as the Validation::run() cannot handle multi-dimention array when it parse through the validation rules.

A quick and dirty work-around I could come up is to use flat-out field names:
like
URL 1 Text: &lt;input type="text" name="data_url_text_1"&gt;
URL 1 Link: &lt;input type="text" name="data_url_url_1"&gt;

URL 2 Text: &lt;input type="text" name="data_url_text_2"&gt;
URL 2 Link: &lt;input type="text" name="data_url_url_2"&gt;

URL 3 Text: &lt;input type="text" name="data_url_text_3"&gt;
URL 3 Link: &lt;input type="text" name="data_url_url_3"&gt;

URL 4 Text: &lt;input type="text" name="data_url_text_4"&gt;
URL 4 Link: &lt;input type="text" name="data_url_url_4"&gt;

URL 5 Text: &lt;input type="text" name="data_url_text_5"&gt;
URL 5 Link: &lt;input type="text" name="data_url_url_5"&gt;

But that's very tiresome and error-prone. So is there anybody have any other thoughts to work around this issue?

Thanks!


  how to create subdomain dinamically in codeigniter
Posted by: El Forum - 01-22-2008, 11:50 PM - Replies (1)

[eluser]Sawariya[/eluser]
hai friends

i want to create subdomains for all registered users ... how it possible.. anybody have idea..
please help me


------------------


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Display a custom error if...
by b126
2 hours ago
Type error in SYSTEMPATH\...
by DXArc
2 hours ago
v4.5.1 Bug Fix Released
by LP_bnss
4 hours ago
Retaining search variable...
by Bosborne
5 hours ago
Getting supportedLocales ...
by InsiteFX
8 hours ago
composer didn't update to...
by Sarog
Yesterday, 03:56 PM
Pipe on url modified in %
by kenjis
Yesterday, 02:52 PM
Best way to create micros...
by kenjis
Yesterday, 02:50 PM
How to use Codeigniter wi...
by kenjis
Yesterday, 02:39 PM
extend url_to helper
by kenjis
Yesterday, 02:33 PM

Forum Statistics
» Members: 85,056
» Latest member: m88ip
» Forum threads: 77,571
» Forum posts: 375,951

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB