Mancent Posted February 28, 2014 Share Posted February 28, 2014 Ok I am storing the files behind the web in a file system. and I am using a getfile.php to read the file.I pass some checks so only the user can get the file unless they have friends and the string looks like this http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=/videos/foldername/output/&getfile=7f7c351ee977c765aa8cd5c7020bc38f.mp4 No when I go to that page it is reading the file as text not as a mp4I thought that the html5 video el would know its a mp4 from the http link provided <video src="getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=/videos/foldername/output/&getfile=c6f46d45bc02173543156c552764c939.mp4" controls></video> but is not working what can I do to make it workthe files are stored here C:\1.8.1xampp\htdocs\wiistream\protected\accounts\1\videos\foldername\output and the webhost is stored here C:\1.8.1xampp\htdocs\wiistream\src\index.php Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/ Share on other sites More sharing options...
requinix Posted February 28, 2014 Share Posted February 28, 2014 Your getfile.php has to tell the browser what type of content it is returning, otherwise it'll just be the default text/html. Looking at the file extension should be enough to decide. For example, .mp4 is video/mp4. header("Content-Type: video/mp4"); Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471086 Share on other sites More sharing options...
Mancent Posted February 28, 2014 Author Share Posted February 28, 2014 Ok so I have to just get the file type and then tell each type the correct header to call. so cool thank you for the help. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471090 Share on other sites More sharing options...
Mancent Posted February 28, 2014 Author Share Posted February 28, 2014 (edited) Ok this works for explore and chrome and firefox but not Safari ill do some searching to see what is needed for Safari so it works with that also Edited February 28, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471091 Share on other sites More sharing options...
Mancent Posted February 28, 2014 Author Share Posted February 28, 2014 anyone know the trick for safari..If I make a just a basic page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <?php header("Content-Type: video/mp4"); ?> </head> <body> </body> </html> and I go to it in safari browser it wants to download a file.. any ideas how to work around that? Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471094 Share on other sites More sharing options...
mac_gyver Posted February 28, 2014 Share Posted February 28, 2014 your getfile.php isn't outputting a web page. the ONLY things it outputs are the correct content type header followed by the file contents. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471098 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 there is nothing wrong with it at all,, the problem I was having was I didn't have quicktime installed on my pc.. Im a windows user and safari is a mac browser, so quicktime was required to play videos as html5 in a windows safari browser on windows. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471111 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 I need help learning how I can debug the headers being called.On the Pc this is working just fine with quicktime installed for sarfari, But on my iphone Ipad the getfile.php readfile($path); will not work I always get a broken play button. <?PHP require_once "core/connect.php"; $root_path = 'protected/accounts'; if(isset($_GET["uid"])) { if(empty($_GET["uid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $uid = $_GET["uid"]; $sql = "SELECT * FROM accounts WHERE id = '".$uid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* Get the users SEC */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $usecurity= $row['security']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["mid"])) { if(empty($_GET["mid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $mid = $_GET["mid"]; $sql = "SELECT * FROM accounts WHERE id = '".$mid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* GET MY ACCESS TOKEN */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $maccesstoken= $row['accesstoken']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["at"])) { if(empty($_GET["at"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ACCESS_TOKEN IS REAL $at = $_GET["at"]; if($maccesstoken == $at) { //ALL IS GOOD RUN MORE CODE } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["security"])) { if(empty($_GET["security"]) && $_GET["security"]== "" ) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER SECURITY IS SET TO PUBLIC FOR UID $security = $_GET["security"]; if($usecurity == $security) { //ALL IS GOOD RUN MORE CODE if($security == 0) { if($uid == $mid) { //everything is ok becasue i am my self and i have my access_token } else { return; } } } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["f_stat"])) { if(empty($_GET["f_stat"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER UID IS FRIENDS WITH MID $f_stat = $_GET["f_stat"]; $sql = "SELECT * FROM accounts_friends WHERE uid = '".$mid."' AND mid = '".$uid."' AND status = '1' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); //ALL IS GOOD THEY ARE FRIENDS } else { //THEY ARE NOT FRIENDS YET return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["path"])) { if(empty($_GET["path"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK PATH FOR USER ID $path = $_GET["path"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["getfile"])) { if(empty($_GET["getfile"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK FILENAME FOR USER ID $getfile = $_GET["getfile"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["thumb"])) { if(empty($_GET["thumb"])) { //RETURN TO HEADER return; } else { $thumb = $_GET["thumb"]; $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$thumb.'/'.$getfile.''; if (file_exists($mypath)) { header('Content-Type: video/mp4'); readfile($mypath,true); } else { //RETURN TO HEADER } } } else { $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$getfile.''; if (file_exists($mypath)) { header('Content-Type: video/mp4'); readfile($mypath,true); //$ext = pathinfo($mypath, PATHINFO_EXTENSION); } else { //RETURN TO HEADER } } I been doing searching about this problem and I see some have the same problem and I found this article but nothing I do works http://mobiforge.com/design-development/content-delivery-mobile-devices Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471145 Share on other sites More sharing options...
jazzman1 Posted March 1, 2014 Share Posted March 1, 2014 Can I see your actual updated php script after reading the article above? Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471147 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 (edited) <?PHP require_once "core/connect.php"; $root_path = 'protected/accounts'; if(isset($_GET["uid"])) { if(empty($_GET["uid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $uid = $_GET["uid"]; $sql = "SELECT * FROM accounts WHERE id = '".$uid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* Get the users SEC */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $usecurity= $row['security']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["mid"])) { if(empty($_GET["mid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $mid = $_GET["mid"]; $sql = "SELECT * FROM accounts WHERE id = '".$mid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* GET MY ACCESS TOKEN */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $maccesstoken= $row['accesstoken']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["at"])) { if(empty($_GET["at"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ACCESS_TOKEN IS REAL $at = $_GET["at"]; if($maccesstoken == $at) { //ALL IS GOOD RUN MORE CODE } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["security"])) { if(empty($_GET["security"]) && $_GET["security"]== "" ) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER SECURITY IS SET TO PUBLIC FOR UID $security = $_GET["security"]; if($usecurity == $security) { //ALL IS GOOD RUN MORE CODE if($security == 0) { if($uid == $mid) { //everything is ok becasue i am my self and i have my access_token } else { return; } } } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["f_stat"])) { if(empty($_GET["f_stat"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER UID IS FRIENDS WITH MID $f_stat = $_GET["f_stat"]; $sql = "SELECT * FROM accounts_friends WHERE uid = '".$mid."' AND mid = '".$uid."' AND status = '1' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); //ALL IS GOOD THEY ARE FRIENDS } else { //THEY ARE NOT FRIENDS YET return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["path"])) { if(empty($_GET["path"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK PATH FOR USER ID $path = $_GET["path"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["getfile"])) { if(empty($_GET["getfile"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK FILENAME FOR USER ID $getfile = $_GET["getfile"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["thumb"])) { if(empty($_GET["thumb"])) { //RETURN TO HEADER return; } else { $thumb = $_GET["thumb"]; $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$thumb.'/'.$getfile.''; if (file_exists($mypath)) { header('Content-Type: video/mp4'); readfile($mypath,true); } else { //RETURN TO HEADER } } } else { $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$getfile.''; if (file_exists($mypath)) { if (is_file($mypath)) { $fileinfo = new finfo(FILEINFO_MIME); $mime_type = $fileinfo->file($mypath); // The function above also returns the charset, if you don't want that: $mime_type = reset(explode(";", $mime_type)); header("Content-type: $mime_type"); //this $mime_type is not set any where and i do not know how to get it if (isset($_SERVER['HTTP_RANGE'])) { // do it for any device that supports byte-ranges not only iPhone rangeDownload($mypath); } else { header("Content-Length: ".filesize($mypath)); readfile($mypath); } } else { echo "Nothing some error"; } //$etag = md5(serialize(fstat($mypath))); //fclose($mypath); //header('Etag: '.$etag); //header('Content-Type: video/mp4'); // readfile($mypath,true); //$ext = pathinfo($mypath, PATHINFO_EXTENSION); } else { //RETURN TO HEADER } } 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 ($range0 == '-') { // 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); } ?> //http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=videos/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp4 ?> using this code now nothing is working not explore or firefox or chrome or sfarai nor the ipad its trick tricky lol.. Edited March 1, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471180 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 (edited) on chrome if I set the file to get it directly no going though the getfile.php the headers read out says this Request URL:http://192.168.0.8/c6f46d45bc02173543156c552764c939.mp4 Request Method:GET Status Code:206 Partial Content Request Headersview source Accept:*/* Accept-Encoding:identity;q=1, *;q=0 Accept-Language:en-US,en;q=0.8 Connection:keep-alive Host:192.168.0.8 Range:bytes=0- Referer:http://192.168.0.8/video.php User-Agent:Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Response Headersview source Accept-Ranges:bytes Connection:Keep-Alive Content-Length:484663 Content-Range:bytes 0-484662/484663 Content-Type:video/mp4 Date:Sat, 01 Mar 2014 21:02:50 GMT ETag:"76537-4f37aa22d8475" Keep-Alive:timeout=5, max=99 Last-Modified:Fri, 28 Feb 2014 17:18:59 GMT Server:Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 now as I use the getfile.php script the header reads out says this and it will not work on chrome for some reason. Request URL:http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=videos/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp4 Request Method:GET Status Code:206 Partial Content Request Headersview source Accept:*/* Accept-Encoding:identity;q=1, *;q=0 Accept-Language:en-US,en;q=0.8 Cache-Control:max-age=0 Connection:keep-alive Host:192.168.0.8 Range:bytes=0- Referer:http://192.168.0.8/video.php User-Agent:Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Query String Parametersview sourceview URL encoded uid:1 mid:1 at:33c1a0d7a97493820ff4dadc42430841 security:1 f_stat:1 path:videos/foldername/output getfile:c6f46d45bc02173543156c552764c939.mp4 Response Headersview source Accept-Ranges:0-42176997 Connection:Keep-Alive Content-Length:42176997 Content-Range:bytes 0-42176996/42176997 Content-Type:video/mp4; charset=binary Date:Sat, 01 Mar 2014 21:05:57 GMT Keep-Alive:timeout=5, max=99 Server:Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 X-Powered-By:PHP/5.4.7 Edited March 1, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471184 Share on other sites More sharing options...
jazzman1 Posted March 1, 2014 Share Posted March 1, 2014 (edited) using this code now nothing is working not explore or firefox or chrome or sfarai nor the ipad its trick tricky lol.. Turn the error reporting on, to see what actually happens! You have a directory/file issue here. Where this mp4 file is? In a web root directory or in videos/foldername/output? PS: Not to mention that this query string is incorrect: URL:http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=videos/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp4 Request Method:GET Edited March 1, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471187 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 (edited) my webroot is on my C drive and I have a J drive that is 3 terabyte external hard drive, that I am using to store all the files. so the getfile.php is in my root directory of the webhost C:\1.8.1xampp\htdocs\wiistream\src\getfile.php and that reads backwards to J:\protected\accounts\$uid\$foldertype\$user_custom_foldername\output\$filename.$ext $foldertype is either{ imagesvideos sounds apps docs }depending on the ext of the file that is getting uploaded decides the folder type and location. the $uid is the users IDthe $user_custom_foldername is what ever the users writes as long as its is chars and no more then 30 chars long then it strips the spacesso the fodlder name can beMy Adobe SoftwareThe database stores the name as is to read laterbut when it is makd the system saves the folder asmyadobesoftware output is only for converted files its not there unless the file is a video or a sound file I use ffmpeg to convert all sound files to mp3 and to oga for different browsers supports and also video files so if the user uploads a mkv or a avi or a flv the system converts it to mp4 and to ogvthe $filename sotres the real file name in database but then md5 it to a random string and the $ext gets added. the getfile.php is working reading from j drive on my PC. and on my network with my other PCs but it will not work on my Ipad or phone.I even tried putting all the files in the root directory of the webhost to see if the getfile.php still had the same problem.. and it dose. Edited March 1, 2014 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471188 Share on other sites More sharing options...
jazzman1 Posted March 1, 2014 Share Posted March 1, 2014 Read the article again. You're completely lost in the tango! Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471189 Share on other sites More sharing options...
Mancent Posted March 1, 2014 Author Share Posted March 1, 2014 I might just go a different direction with it,, I want to store the files on the external drive,, and I was thinking I might just make a temp webroot folder that will get the file and copy it to the temp folder on the site so its local when being read, but the rest of the time its dormant. but I do not know if that is a bad idea or not, can php copy from j drive c drive temp folder? then update database to read from temp table where uid and foldername filename.. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471190 Share on other sites More sharing options...
jazzman1 Posted March 1, 2014 Share Posted March 1, 2014 Before to get yourself into a different direction you need to step back trying actually to understand what causes your current problems. The best way is to teach yourself how to debug your php scripts. Brake up your script(s) into small pieces and fragments of data and debug them. You could make a google research - "how to debug in php", for instance. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471193 Share on other sites More sharing options...
Mancent Posted March 2, 2014 Author Share Posted March 2, 2014 I had to do this to make it work. Still need to add more to it,, for the different file ext. <?PHP require_once "core/connect.php"; $root_path = '../protected/accounts'; if(isset($_GET["uid"])) { if(empty($_GET["uid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $uid = $_GET["uid"]; $sql = "SELECT * FROM accounts WHERE id = '".$uid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* Get the users SEC */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $usecurity= $row['security']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["mid"])) { if(empty($_GET["mid"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ID IS REAL $mid = $_GET["mid"]; $sql = "SELECT * FROM accounts WHERE id = '".$mid."' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); /* GET MY ACCESS TOKEN */ if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $maccesstoken= $row['accesstoken']; } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["at"])) { if(empty($_GET["at"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER ACCESS_TOKEN IS REAL $at = $_GET["at"]; if($maccesstoken == $at) { //ALL IS GOOD RUN MORE CODE } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["security"])) { if(empty($_GET["security"]) && $_GET["security"]== "" ) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER SECURITY IS SET TO PUBLIC FOR UID $security = $_GET["security"]; if($usecurity == $security) { //ALL IS GOOD RUN MORE CODE if($security == 0) { if($uid == $mid) { //everything is ok becasue i am my self and i have my access_token } else { return; } } } else { return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["f_stat"])) { if(empty($_GET["f_stat"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK IF USER UID IS FRIENDS WITH MID $f_stat = $_GET["f_stat"]; $sql = "SELECT * FROM accounts_friends WHERE uid = '".$mid."' AND mid = '".$uid."' AND status = '1' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); //ALL IS GOOD THEY ARE FRIENDS } else { //THEY ARE NOT FRIENDS YET return; } } } else { //RETURN TO HEADER return; } if(isset($_GET["path"])) { if(empty($_GET["path"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK PATH FOR USER ID $path = $_GET["path"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["getfile"])) { if(empty($_GET["getfile"])) { //RETURN TO HEADER return; } else { //DO A SELECT MYSQL TO CHECK FILENAME FOR USER ID $getfile = $_GET["getfile"]; } } else { //RETURN TO HEADER return; } if(isset($_GET["thumb"])) { if(empty($_GET["thumb"])) { //RETURN TO HEADER return; } else { $thumb = $_GET["thumb"]; $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$thumb.'/'.$getfile.''; if (file_exists($mypath)) { //header('Content-Type: video/mp4'); //readfile($mypath,true); } else { //RETURN TO HEADER } } } else { $mypath = $root_path.'/'.$uid.'/'.$path.'/'.$getfile.''; if (file_exists($mypath)) { $fileinfo = new finfo(FILEINFO_MIME); $mime_type = $fileinfo->file($mypath); // The function above also returns the charset, if you don't want that: // $mime_type = reset(explode(";", $mime_type)); header("Content-type: $mime_type"); $ext = pathinfo($mypath, PATHINFO_EXTENSION); if($ext == "jpg") { readfile($mypath,true); return; } if($ext == "mp3") { readfile($mypath,true); return; } if(preg_match("/chrome/",strtolower($_SERVER['HTTP_USER_AGENT'])) || preg_match("/safari/",strtolower($_SERVER['HTTP_USER_AGENT'])))//AND IPHONE IPAD AND ANY OTHER ONES THAT NEED IT { $filetemp = "filetemp"; if(!file_exists($filetemp)) { mkdir($filetemp,0777); chmod($filetemp,0777); //echo "Creating root and uid and folder"; } // Let's make sure the file exists and is writable first. if (is_writable($getfile)) { if (!$handle = fopen($getfile, 'a')) { echo "Cannot open file ($getfile)"; exit; } // Write to our opened file. if (fwrite($handle, "") === FALSE) { echo "Cannot write to file ($getfile)"; exit; } echo "Success: Added File Name $getfile To Temp Directory."; fclose($handle); } else { echo "The file $getfile is not writable"; exit(); } copy($mypath,$filetemp.'/'.$uid);//Ok so every user can have a temp file that will get over wrote each time they switch videos if they are using thier phones or ipads or some other device that can not use the getfile corny header('location: filetemp/'.$uid.''); } else { //echo $_SERVER['HTTP_USER_AGENT']; //return; if($ext == "mp4") { readfile($mypath,true); return; } echo $ext; } } else { //RETURN TO HEADER } } //http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=sounds/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp3 //http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=videos/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp4 //http://192.168.0.8/getfile.php?uid=1&mid=1&at=33c1a0d7a97493820ff4dadc42430841&security=1&f_stat=1&path=images/foldername&getfile=photo-thumb-98147.jpg ?> Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471196 Share on other sites More sharing options...
jazzman1 Posted March 2, 2014 Share Posted March 2, 2014 path=sounds/foldername/output&getfile=c6f46d45bc02173543156c552764c939.mp3 There is an error here, since typical usage of a query fragment never includes the hierarchy ("/") character, and the query component is not normally used within relative references. Some clients (browsers) ignore them some not, trying to merging it as a part of the base path. Quote Link to comment https://forums.phpfreaks.com/topic/286619-readfilemypath/#findComment-1471224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.