PHP - Curl And Images+video
I am practicing php with a local server running and I created a class that uses curl to open pages, fetch the html, put it into a DOMDocument, parse it, etc...I began following links and downloading images and checking their mime types so I know how to handle it. There isn't really much information about doing it with video files though like mpeg, mov, etc...When I try simply following the link and downloading it locally it works, but I get no mime type, or a wierd mime type that doesn't make sense and it will only store a blank file (but it all downloads ok) I just can't play it. Anybody know anything about doing video stuff with php?
Similar Tutorialsthis script saves the image from a url to the folder were this script is saved, how can i make this code save images into specific folder such as "/image/poster_image/" <?php $img[]='http://images.rottentomatoescdn.com/images/redesign/poster_default.gif'; foreach($img as $i){ echo $i; save_image($i); // if(getimagesize(basename($i))){ // echo '<h3 style="color: green;">Image ' . basename($i) . ' Downloaded OK</h3>'; // }else{ // echo '<h3 style="color: red;">Image ' . basename($i) . ' Download Failed</h3>'; // } } //Alternative Image Saving Using cURL seeing as allow_url_fopen is disabled - bummer function save_image($img,$fullpath='basename'){ if($fullpath=='basename'){ $fullpath = basename($img); } $ch = curl_init ($img); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } ?> I am trying to upload images to Imageshack directly form my site with Imageshack API, using the code bellow: index.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form action="curl-form.php" method="post" enctype='multipart/form-data'> <input type="file" id="foto" name="foto" /> <input type="submit" value="Enviar" /> </form> </body> </html> img.php <?php $data = array(); $data['fileupload'] = '@' . $_FILES["foto"]['tmp_name']; $data['key'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $data['email'] = 'email@email.com'; $data['rembar'] = 'yes'; $data['optsize'] = '96x96'; $data['xml'] = 'yes'; $post_str = ''; foreach($data as $key=>$val) { $post_str .= $key.'='.urlencode($val).'&'; } $post_str = substr($post_str, 0, -1); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.imageshack.us/upload_api.php'); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 240); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch ); curl_close($ch ); if (strpos ( $response, '<' . '?xml version="1.0" encoding="iso-8859-1"?>' ) === false) { return NULL; } else { $xml = new SimpleXMLElement ( $response ); return array ( "image" => $xml->image_link, "thumb" => $xml->thumb_link ); } ?> When I upload an image, the following error occurs: "Sorry, but we've detected that unexpected data is received. Required parameter 'fileupload' is missing or your post is not multipart/form-data" What is wrong with the code? How can I send enctype='multipart/form-data' with cURL? good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. I have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
I want to grab the title of a cl page using curl, can anyone help me with this?
I have the urls stored in a table I just need can't get it to read the title of the post in CL, let me know if you can help.
hy all long time no see recently i did find this problem i'm trying to login to a webpage with curl ,but without success ,ofcourse the basic posting is not the problem xD but the page have a hidden field (for security) so everytime you load the page it changes so post wont work if you first use get to take the page and extract the hash from it. the page contains something like input type= hidden value=A RANDOM VALUE THAT CHANGES EVERYTIME without that value passed to post it wont login. anyone knows how can i pass it so the post will be valid? thank you I am using the following code. Code: [Select] $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); I was given a .cer file should I set CURLOPT_SSL_VERIFYPEER to TRUE and set the path to the .cer file? Any help would be awesome. Thanks Hi. I am fairly new with cURL.
I have a URL like example.com/index.php?something=value&somethingtwo=valuetwo
How can I get those values and print them out?
I've got this code, but have no idea what to do next, please help guys!
<?php function get($url, $params=array()) { $url = $url.'?'.http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return $response; } // Sample call echo get('https://www.example.com/index.php', array('something'=>'value', 'somethingtwo'=>'valuetwo')); ?> I have a large list of websites that have allowed me to submit my website and description every 24 hours to there sites. I'm really getting tired of sitting by my computer and submitting the information to every site manually. I never understood curl and php dom stuff. does anyone have a easy code where I can post a pre scripted text of my information into three boxes and it auto submits every 24 hours to the websites? The boxes look like this Code: [Select] <input maxlength="255" value="http://" name="sPlugurl" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="30" value="Sitename" name="sPlugname" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="255" value="Description" name="sPlugdescription" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input type="submit" value="Dump" style="background-color: #656565; font-family: Verdana; color: <? echo ;?>; font-size: 10pt; border: 1px solid #0C0C0C"> the php script would auto fill out the value of the first 3 boxes with my info and then the program would submit it to there forum. I looked on google but nothing I found I can figure out? Hey guys I'm trying to log into this website using curl. I did some reading and think I'm pretty close but I cant get the login working It just returns nothing. there is a commented out part which is the page i'm trying to load after I successfully login.
<? $username = 'xxxxxxx'; $password = 'xxxxxxx'; $postinfo = "username=".$username."&password=".$password; $cookie="cookie.txt"; $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_URL, 'https://weblogin.asu.edu/cas/login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); $data = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } echo $data; curl_close($ch); // //page with the content I want to grab after logging in (test after login works) // curl_setopt($ch, CURLOPT_URL, "https://webapp4.asu.edu/myasu/"); // curl_setopt($ch, CURLOPT_POST, false); // $data = curl_exec($ch); // if (curl_error($ch)) { // echo curl_error($ch); // } ?>I'm not sure but I think im maybe missing some other parts the form needs? How do I see exactly what I need to send? hello i`m new here . i need someone to build a php script with CURL and <iframe> i can pay for the script PM back or email me here icemerc@yahoo.com I have just installed cURL and am learn to use it but I'm not sure exactly what I am doing. For example I have a page with this code on it. if($_GET['number'] == "6") { echo("<p>the number is six</p>"); } Then I am trying to use cURL to send the number 6 to this page so that it returns "the number is 6". However I am just getting an output of "1". Below is the code I am using to try to get the output of "the number is 6". $ch2 = curl_init(); curl_setopt($ch2,CURLOPT_URL,'http://localhost/crawler/crawlertest.php'); curl_setopt($ch2, CURLOPT_POST, 1); curl_setopt($ch2,CURLOPT_POSTFIELDS,'number=6'); $return = curl_exec($ch2); echo ($return); curl_close($ch2); Thanks for any help Ok, I'm new to this and I don't know much about PHP, much less Curl and how to use the functions inside of PHP: http://us.php.net/manual/en/book.curl.php However, I need to do something with this. I have to create this curl.php file, inside that file I need to take the $_POST array and send it to a different php file... I'm not sure how to do this. And yes, I only need that. I'd post the source, but my company's proprietary policies prevent me. Hey guys I need help with curl php . I cannot get info from other website. I have been trying to get single post but I'm gettig the whole page or more than one post. I get tutorial from youtube, but for some reason its not working. Does anyone can help me with simple example ? code prehaps? I have the following code but i can seem to log into the page can somebody tell me what is wrong please <?php error_reporting(E_ALL); $maindir = dirname(__FILE__) . DIRECTORY_SEPARATOR; include($maindir.'functions.php'); set_time_limit(0); ini_set('memory_limit','128M'); $curl_handle = curl_init(); define("SSL_CA_FILE", ".\\temp\\ssl"); define("COOKIE_FILE", "cookies.txt"); $source_file = $maindir.'login_info.txt'; // report errores error_reporting(-1); $maindir.'login_info.txt'; $fp_s = fopen($source_file, 'r'); $ch = curl_init(); //curl_followlocation set the curl to follow the site and get the final web page if the // website has redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)'); // save cookie curl_setopt($ch, CURLOPT_COOKIEJAR, $maindir.'cookie.txt'); // get cookie curl_setopt($ch, CURLOPT_COOKIEFILE, $maindir.'cookie.txt'); // not to print out the results curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $account = '*****'; $password = '*****'; if(file_exists(COOKIE_FILE)) { unlink(COOKIE_FILE); } $qryString = 'email='.urlencode($account).'&pass='.urlencode($password).'&login_type=1'; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $qryString); curl_setopt($ch, CURLOPT_URL, 'https://secure.gumtree.ie/account/login'); $page = curl_exec($ch); echo $page; // close session curl_close($ch); ?> What exactly is cURL? What are alternatives to it? I am reading some code for submitting payment info to a Payment Gateway and trying to understand how cURL plays into this?! Thanks, Debbie Hello I want download a webpage with curl on my host using php. but when I use curl didn't download this page, if I change curl to file_get_contents and use it download this page. please help me to resolve my problem. URL is : www.ebook33.com CUL code is : function Get($url) { $hCurl = curl_init($url); curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, TRUE); $ret = curl_exec($hCurl); curl_close($hCurl); return ($ret); File get content code is : file_get_contents($url); Hi there, I wanted to create files from my phpscript. So I used the most obvious function, fopen(). It didn't work on my server and contacted the administrator, who said fopen() was disabled for security reasons, and that I should use cURL. So I did what everyone would do; I googled it. Found the php.net curl manual, but can't really comprehend what it sais. So I have a few questions: 1) Can you create .php files with cURL? 2) How? 3) How do I then write php-content in the file? Please try to explain rather detailed and simplified, I've never been good at quickly understanding all these things. Thanks a lot! Hello, I'm new to lot of this and especially php. I'm having hard time with one of my app that I created. If you go to ticketlawyerorlando.com/sms5.html and you try to send text, (which is set to go to only one number (mine)) than I get error code from php that is supposed to curl it. Error: Warning: curl_setopt() [function.curl-setopt]: Invalid curl configuration option in /home/content/s/j/1/sj10mil/html/ticketlawyerorlando/sms5.php on line 10 SUCCESS My Html code is : Code: [Select] <html> <body> <br/> <form action="sms5.php" method="post"> <b>Your Phone Number:</b> <input type="text" name="to" /> <br/> <b>Message:</b> <input type="text" name="msg" /> <br/> <input type="submit" /> </form> </body> </html> My sms5.php code is : Code: [Select] <html> <head> <title>SMS STATUS</title> </head> <body> <?php //print $to; //print $msg; $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_GET,1); curl_setopt($curl_handle, CURLOPT_URL,'https://api.tropo.com/1.0/sessions?to=3213314633&msg=test4&token=010fc32265db5444bbf84e92bd28f1887395ce3ade6cf69e1424d586add66b17bdc7c1d8061803f1c2319d66'); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,5); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,2); $response = curl_exec($curl_handle); $code = curl_getinfo($curl_handle,CURLINFO_HTTP_CODE); //print $code; //print $response; print "SUCCESS"; curl_close($curl_handle); ?> </body> </html> In my php, the URL that's being curled, in the part where it says "test4" that should be actual message that is typed in the form but I don't know what kind of parameter to insert there in order for it to send message that's written, it always sends message "test4". Please, if you could help me I would greatly appreciate it. Thank You so much again. MOD EDIT: code tags added |