Jump to content

optikalefx

Members
  • Posts

    363
  • Joined

  • Last visited

    Never

Posts posted by optikalefx

  1. im trying to play large files from under the webroot to an html5 video tag.  Nothing is working.

    So i made a sym link to the folder and just header_location to the file.

     

    and now when i tell html5 to play /video/play it works

     

    but, when i open firebug net tab, i can see the requests are for the full URL to the video file, not the video/play that html5 is using.  Obviously because header_location will show the full path.

     

    Is there any ways you guys think what im doing is possible? If not, how can i make it that the browser can play the video files, but the user can't go there directly in their browser?

  2. So i have a large video files, 1.5 gigs even.

    I made an html5 video player where the source is a php file.

    The php file is supposed to go below the web root and serve the video file to the html5 video tag.

     

    This all works just fine if the video using a script that uses HTTP_RANGE to serve the file in parts to the client.

    The problem is, once one video is playing - i can't do anything else.  Its like the server locks up. I mean i can scrub that video, i can do anything to that page.  I just can't navigate away.  But i can open a new browser and play a new video.  But again, once that first one is playing, or even paused, i can't do anything else.

     

    That is of course until i restart apache.

     

    Any ideas on how to stream these large files better? I have a feeling they are set to stream and never stop.

    This is the code for that

     

    function rangeDownload($file) {
    
    $fp = @fopen($file, 'rb');
    
    $size   = filesize($file); // File size
    $length = $size;           // Content length
    $start  = 0;               // Start byte
    $end    = $size - 1;       // End byte
    // Now that we've gotten so far without errors we send the accept range header
    /* At the moment we only support single ranges.
     * Multiple ranges requires some more work to ensure it works correctly
     * and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
     *
     * Multirange support annouces itself with:
     * header('Accept-Ranges: bytes');
     *
     * Multirange content must be sent with multipart/byteranges mediatype,
     * (mediatype = mimetype)
     * as well as a boundry header to indicate the various chunks of data.
     */
    header("Accept-Ranges: 0-$length");
    // header('Accept-Ranges: bytes');
    // multipart/byteranges
    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
    if (isset($_SERVER['HTTP_RANGE'])) {
    
    	$c_start = $start;
    	$c_end   = $end;
    	// Extract the range string
    	list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
    	// Make sure the client hasn't sent us a multibyte range
    	if (strpos($range, ',') !== false) {
    
    		// (?) Shoud this be issued here, or should the first
    		// range be used? Or should the header be ignored and
    		// we output the whole content?
    		header('HTTP/1.1 416 Requested Range Not Satisfiable');
    		header("Content-Range: bytes $start-$end/$size");
    		// (?) Echo some info to the client?
    		exit;
    	}
    	// If the range starts with an '-' we start from the beginning
    	// If not, we forward the file pointer
    	// And make sure to get the end byte if spesified
    	if ($range == '-') {
    
    		// The n-number of the last bytes is requested
    		$c_start = $size - substr($range, 1);
    	}
    	else {
    
    		$range  = explode('-', $range);
    		$c_start = $range[0];
    		$c_end   = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
    	}
    	/* Check the range and make sure it's treated according to the specs.
    	 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
    	 */
    	// End bytes can not be larger than $end.
    	$c_end = ($c_end > $end) ? $end : $c_end;
    	// Validate the requested range and return an error if it's not correct.
    	if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
    
    		header('HTTP/1.1 416 Requested Range Not Satisfiable');
    		header("Content-Range: bytes $start-$end/$size");
    		// (?) Echo some info to the client?
    		exit;
    	}
    	$start  = $c_start;
    	$end    = $c_end;
    	$length = $end - $start + 1; // Calculate new content length
    	fseek($fp, $start);
    	header('HTTP/1.1 206 Partial Content');
    }
    // Notify the client the byte range we'll be outputting
    header("Content-Range: bytes $start-$end/$size");
    header("Content-Length: $length");
    
    // Start buffered download
    $buffer = 1024 * 8;
    while(!feof($fp) && ($p = ftell($fp)) <= $end) {
    
    	if ($p + $buffer > $end) {
    
    		// In case we're only outputtin a chunk, make sure we don't
    		// read past the length
    		$buffer = $end - $p + 1;
    	}
    	set_time_limit(0); // Reset time limit for big files
    	echo fread($fp, $buffer);
    	flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
    }
    
    fclose($fp);
    
    }
    

  3. I've installed many linux servers, but this server, is making me feel like an idiot.  Its running a LAMP stack on a ubuntu 10 box.  I have ssh access to root.

     

    the document root is /var/www and that works fine

    i have a .htaccess file inside of /var/ww that has some jibberish.  I SHOULD be getting an internal server error.  When i paste this into my localhost i get that server error, but not on this server.  I also tried a correct htaccess file, but it doesn't work either. So my hunch is that apache is not using the htaccess file.

     

    In my apache2.conf file

     

    AccessFileName .htaccess
    

     

    is set, and i've restarted apache.

    I have no idea what is going on, never had this happen before.  Any ideas? thanks!

  4. My php needs a wrapper function for require.  Because there is a specific naming scheme thats always applied, and i want to log every require.

     

    so i made $this->_require($file)

    The problem is, the scope isn't carried over, so any variables that exists in the method that called _require don't exist in the required file. But they DO exist when i don't use the wrapper function.

     

    So it seems in order for the variable scope to carry into the required file the require itself has to be in the same function call.

     

    Is there any solution to me being able to make a wrapper method for require?

     

    thanks!

  5. Is this possible?

    I have a PHP file that serves a file (which is below the web root). That works fine and the download dialog is presented when directly accessed.

    Im building and API however, and that file needs to be served via HTTP Request.

     

    Im trying to get it working with cURL but right now its just outputting the raw byte data to the screen.  Anyone had success or know what I need to try to be able to call that PHP file with cURL and have the browser try to download the file?

     

     

    (i've tried a lot of combinations of settings for this)

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_URL,$remote);
    curl_setopt($ch,CURLOPT_BINARYTRANSFER,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);
    return curl_exec($ch);
    

     

    // side note

    I'm hoping the cURL settings don't matter too too much because a C# program will need to request the download.

  6. That's all well and good, but if the OP has permission he may as well make a proper connection to the database and just use.

     

    Unfortunately however, the OP isn't being very helpful with his questions / responses to other questions.

     

    From what i can gather OP has access but most likely not directly to the database.  Because it seems OP knows how to straight connect to a DB but for some reason this other DB isn't directly connectable.  Therefore it's probably on a remote system, and hes trying to connect and use it via a URL and that most closely resembles a remote HTTP request such as CURL.

     

    I guess. lol.

     

  7. @OP whatever website hosts the remote database, get them to write a small simple PHP script that acts like a private API.  That way you can use CURL to get data from the remote database.

     

    Where $nvp below is a URL variable thing. like &db=customers&customer_id=1&fname=frank

     

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"http://www.website.com/page.php" );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    // Set the request as a POST FIELD for curl.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);
    
    // Get response from the server.
    echo curl_exec($ch);
    

     

    then BOOM using a URL to get data from a remote database.

  8. leave the CSS alone. CSS files are not meant to by dynamic.  Style is separate from function.

     

    If you want the style to change on load, then change the style with JS onload.  you can use PHP inside of JS as normal, and have the JS change the style when needed.

  9. I've been able to serve files forever now, and finally had a request for docx.  Well, i used the mime type i got from microsofts site

    application/vnd.openxmlformats-officedocument.wordprocessingml.document

    and it says corrupt file whenever its served.

     

    now, i've tried with many different files to make sure it wasn't just a bad test, its definetly how im serving it.  Are there special headers? or has anyone ever been successful at this?

     

    It is actually serving the file correctly but only after 2 pop up errors and warnings.  So the content is there, its just throwing some kind of error.

     

    Here is some code.

    and before you ask, no there isn't a problem with the decrypt or encrypt method, i've tried with those off as well.  When decrypted, i can double click and open docx just fine, but when i try to server it, i get corrupt errors.

     

    function _serveFile($key) {
    	ini_set("memory_limit","128M");
    	$file = $this->_data[$key];
    	if(isset($file) && !empty($file)) {
    		$ext = end(explode(".", $file));
    		$allowed = array("doc","rtf","txt","pdf","xls","jpg","png","tiff","jpeg");
    		//if(in_array($ext,$allowed)) {
    		if(1) {
    			switch($ext) {
    				case "txt":
    					$type = "text/plain";
    					break;
    				case "rtf":
    					$type = "application/rtf";
    					break;
    				case "doc":
    					$type = "application/msword";
    					break;
    				case "docx":
    					$type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    					break;	
    				case "xls":
    					$type = "application/vnd.ms-excel";
    					break;
    				case "pdf":	
    					$type = "appliction/pdf";
    					break;
    				case "png":	
    					$type = "image/png";
    					break;	
    				case "gif":	
    					$type = "image/gif";
    					break;	
    				case "jpg":
    				case "jpeg":	
    					$type = "image/jpeg";
    					break;	
    				case "tiff":	
    					$type = "image/tiff";
    					break;		
    				default:
    					$type = "application/octet-stream";
    					break;		
    			}
    			$name = $this->_data['first_name']."_".$this->_data['last_name']."_".$key.".".$ext;
    			$tmp = $this->_createDecryptedTmpFile(UPLOAD_DIR.DS."files".DS.$file);
    
    
    			header("Pragma:public");
    			header("Expires:0"); 
    			header("Cache-Control:must-revalidate,post-check=0,pre-check=0"); 
    			header("Cache-Control:private",false);
    			header("Content-Type:application/force-download");
    			header("Content-Type:application/download");
    			header("Content-Description:File Transfer");
    			header("Content-type:".$type);
    			header("Content-disposition: attachment; filename=".$name);
    			header("Content-Length:".filesize($tmp));
    
    
    			echo file_get_contents($tmp);
    		} else {
    			echo "The file type $ext is not allowed";
    		}	
    	}
    }
    

     

     

    thanks!!!

     

  10. I much better understand inheritance now.

     

    My original thought was that the parent class had properties that all any sub class could change, as in the subclass is changing the parent's property.  But that is not inheritance.  That is just nonsense.  The parent class defines the variables that may exist in the subclass.  And every subclass has INSTANCES of the parent's properties, because the child class inherit those properties.

     

    So if i have a a property in the parent class called $this->myvar.  Sub class 1 sets $this->myvar to "hello"  When subclass 2 gets instantiated, it is a NEW copy of the base class, and therefore the value of $this->myvar is not "hello" it is simply blank.  Upon changing $this->myvar in subclass 2, subclass 1 is STILL "hello"

  11. ok so i wrote that wrong.

     

    here is a full php file

     

    <?php
    
    class base {
    var $myvar = "start";
    function changeValue() {
    	$this->myvar = "changed";
    }
    }
    
    class extender extends base {
    function showMyvar() {
    	echo $this->myvar;
    }
    }
    
    class extender2 extends base {
    function extender2() {
    	$this->myvar = "2 changed";
    }	
    }
    
    
    $test = new extender;
    $test2 = new extender2;	// should change the value
    echo $test->myvar;		// prints as start
    
    ?>
    

     

    why can't i change the base class variable?

  12. I know the problem must be dumb, but this is killing me.  I have 2 classes, one extends another one.  The base class has a variable and later in the code the base class changes that variable.  But after i instantiate the extended class it only has the original value.

     

    echo $this->myvar;	// start
    $this->myvar = "test ";
    echo $this->myvar; // test
    require_once("controllers/blog.controller.php");
    $blog = new Blog();
    echo $blog->myvar;	// start ???????
    

     

    here is app.controller.php

    class App {
    
    var $myvar = "start ";
    }
    

     

    and here is blog.controller.php

    class Blog extends App {
    
    }
    

     

     

    that variable $this->myvar should be the same all the time right? ahhhhhhhhhhh

  13. d@abaR But there is obviously a need for specific app markets. For example, pick any digital market.  Lets say kitchen computers.  Although not a huge market, is there any place you can get all apps focuses for the kitchen? Made specifically for computers that will sit in the kitchen? More importantly touch computers that will be in the kitchen that should have apps based soley on touching the screen.  What I'm saying is that yes you can google something, but more and more are the mass public proving that they like apps, they like apps being in 1 place and they like apps that are organized and focused and so they can see what is popular.  More importantly they like that apps are relatively cheap.

     

    @tibberous I've been building a download only store for a while now, and its a lot harder than you think.  Not harder as in difficult, probably not the right word, but you have many different challenges than selling normal products.  For example, there is no shipping, no weight, not inventory not attributes no options.  Those things are  HUGE (and headachy part) of building a normal store.

    With downloads you have new challenges, uploading, online storage security, serving downloads in parts not at once, keep track of downloads, serial code generation, license key generation, instant downloading... i mean the list goes on.

     

  14. I don't wanna sound stupid, or give a way a great idea, but I can't seem to find software out there that is made specifically for downloadable "apps" if you will.  Where users can upload their own to the store, and they can be free or paid.  Nothing to do with hardware, just downloadable software. There would be 3 types of users in my eyes, admins, developers and customers. admins and developers share the backend where admins can see more, and customers only can see the front end and their profile.

     

    Does anything like this exist? Or should i get to work making it? lol

  15. 1. Users will not be able to bookmark pages on your website. If you use the DOM to change the layout the url will not change. This also has a massive impact on search engine ranking.

    2. If users do not run Javascript then your site is inaccessible.

     

    lol

     

    1) Use hashes to allow dom changing bookmarks.  like if you click on a link that does a dom change site.com/#alink

    2) If there is no js, then the links will just execute the link instead of load the content, its seamless.

  16. Yea this is easy.

    Just catch your Nav links via javascript, and use ajax to get the result of the link and replace the main content. Which of course would be behind the video.

     

    Or even easier than worrying about layering, have your ajax call return a json object of 4 pieces of content. data.top data.left data.right and data.bottom.

     

    if your page is layed out like

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

     

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

    |        | video |        |

    |        |          |        |

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

     

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

     

    then just leave the div with your video alone, and just use javascript to replace the contents of the 4 surrounding divs.  And again the easiest way to return 4 things from ajax is using json.

     

    in php that would look like

     

    $data['top'] = "html code here";
    $data['left'] = "html code here";
    etc...
    

     

    then echo json_encode($data);

     

    and then on the client, lets say ur using jquery

    $("a").click(function() {
      var url = $(this).attr("href");
      $.get(url,function(data) {
        $("#topDiv").html(data.top);
       $("#leftDiv").html(data.left);
       etc...
    },"json");
    });
    

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