Cory94bailly Posted September 25, 2009 Share Posted September 25, 2009 Hi guys, I'm currently working on a script to download files to a user.. What would work best (and FASTEST)? Downloading the file to the server then serving to the user OR having it go straight to the user? I know obviously that it going straight to the user would be best but I'm not sure how to with cURL.. And yes, it must be with curl because I'm using a login and cookie.. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 BUMP :rtfm: Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 Quick example, from google. good luck! <?php $a=0; $timevalue = substr(time(),3,11); $photoname = $timevalue.$a.'.jpg'; $ch = curl_init("http://www.somedomain.com/images/some%20folder/some%20image%20file.jpg"); $fp = fopen($photoname, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?> Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 Quick example, from google. good luck! <?php $a=0; $timevalue = substr(time(),3,11); $photoname = $timevalue.$a.'.jpg'; $ch = curl_init("http://www.somedomain.com/images/some%20folder/some%20image%20file.jpg"); $fp = fopen($photoname, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?> I tried this and it does absolutely nothing: $ab = curl_init($_POST['link']); $cd = fopen($_POST['link'], "r"); curl_setopt($ab, CURLOPT_FILE, $cd); curl_setopt($ab, CURLOPT_HEADER, 0); curl_exec($ab); Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 Please read this, and also use Google to get examples. We dont mind but we like code that didn't work after you tried it properly .... http://phpsense.com/php/php-curl-functions.html Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 I was wondering if it was possible to have it go STRAIGHT from the server that I'm curl'ing into TO the user... I guess downloading to my server then serving it to the user would work too but not very well because it's slower.. Is there any other way to server it straight to the user? I could send them straight to the url but it needs the cookie (i think), because curl is logging in to a form. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 sorry but all php programmers love this code snippet, to force downloads to a user,straight forward and works very good. http://www.phpfreaks.com/forums/index.php/topic,95433.0.html thanks to OBER what a man...... Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 sorry but all php programmers love this code snippet, to force downloads to a user,straight forward and works very good. http://www.phpfreaks.com/forums/index.php/topic,95433.0.html thanks to OBER what a man...... I know header location it's just that it needs to be through cURL because I'm logging into an html form and you need the cookie to download the file.. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 when you log into this html page, that your using Curl for, you should be getting the results on a page that curl just logged into are YOU? Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 why because when you log into this html page you using Curl for, you should be getting the results on a page that curl logged into are YOU? Yes, it is showing me the members area but if I do a header redirect, I personally do not have the cookie, the server does.. So it tells me to login. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 can it be done this way then. just saw this on google interesting innit? <?php $url = 'http://www.tibia.com/logging/url'; // The URL to the accountmanagement page $f1 = 'accnr'; // Name of field1(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!) $f2 = 'pass'; // Name of field2(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!) $v1 = $_POST['acc']; // Value of field1(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!) $v2 = $_POST['pw']; // Value of field2(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!) $find = 'Welcome to your account'; // String to search for in the page you've logged in on $postchars = http_build_query( array($f1 => $v1, $f2 => $v2) ); $stream = stream_context_create( array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => htmlspecialchars_decode( $postchars ) ) ) ); // Creates an array of the sourcecode, and inputs the values of the field1 and field2 $content = file_get_contents($url, false, $stream); // Gets the sourcecode from the new page that is loaded after the input of the values. $search = strpos($content, $find); // Search the sourcecode for the specific string in the variable "find" if($search === false){ echo 'The login seems to be incorrect. Please try again, or check if you have a valid account'; } // If the string wasn't found else { echo 'Your account is valid!'; } // If the string was found ?> stream_context_create (looks promising? http://us2.php.net/manual/en/function.stream-context-create.php Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted September 26, 2009 Author Share Posted September 26, 2009 can it be done this way then. just saw this on google interesting innit? <?php $url = 'http://www.tibia.com/logging/url'; // The URL to the accountmanagement page $f1 = 'accnr'; // Name of field1(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!) $f2 = 'pass'; // Name of field2(ON THE WEBSITE YOU'RE TRYING TO LOGIN ON!) $v1 = $_POST['acc']; // Value of field1(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!) $v2 = $_POST['pw']; // Value of field2(FROM THE WEBSITE YOU'RE TRYING TO LOGIN FROM!) $find = 'Welcome to your account'; // String to search for in the page you've logged in on $postchars = http_build_query( array($f1 => $v1, $f2 => $v2) ); $stream = stream_context_create( array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => htmlspecialchars_decode( $postchars ) ) ) ); // Creates an array of the sourcecode, and inputs the values of the field1 and field2 $content = file_get_contents($url, false, $stream); // Gets the sourcecode from the new page that is loaded after the input of the values. $search = strpos($content, $find); // Search the sourcecode for the specific string in the variable "find" if($search === false){ echo 'The login seems to be incorrect. Please try again, or check if you have a valid account'; } // If the string wasn't found else { echo 'Your account is valid!'; } // If the string was found ?> stream_context_create (looks promising? http://us2.php.net/manual/en/function.stream-context-create.php Even if that does work (Logging in), I don't see how it would allow the user to download the file.. Quote Link to comment 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.