TheSky Posted April 12, 2011 Share Posted April 12, 2011 i want add filename as $name how i need do it? pleas help <?php // show errors error_reporting(1); // get as ? $url=$_GET['url']; // value of script $website = $url; $file = 'data.txt'; $referer = 'xxxx.xx'; $useragent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'; // add name ? $name = $url; // connect $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_USERAGENT,$useragent); curl_setopt($curl_handle,CURLOPT_AUTOREFERER,$referer); curl_setopt($curl_handle,CURLOPT_URL,$website); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,5); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); // error log print "<b>Fetching <b>"; if (empty($buffer)) { print '<font color="red">' . ERROR . '</font><br>'; } else print '<font color="green">' . OK . '</font><br>'; // let's write now // Open the file to get existing content $current = file_get_contents($file); // error log print "<b>Writing <b>"; if (file_exists($file)) { print '<font color="green">' . OK . '</font><br>'; } else print '<font color="red">' . ERROR . '</font><br>'; // Append a new person to the file $current .= "$buffer \w"; // Write the contents back to the file file_put_contents($file,$buffer); curl_close($curl_handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/ Share on other sites More sharing options...
TheSky Posted April 12, 2011 Author Share Posted April 12, 2011 so i just basicaly need $name=$url but how i can save it ;( pleas help Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200430 Share on other sites More sharing options...
devWhiz Posted April 12, 2011 Share Posted April 12, 2011 I don't understand the question Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200432 Share on other sites More sharing options...
TheSky Posted April 12, 2011 Author Share Posted April 12, 2011 im writing file_put_contents($file,$buffer); but how i can add name on file if i try file_put_contents($name,$file,$buffer); it dose not work so i need help im kind of newbie on php i hope, you understand me now better Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200433 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 Not really sure if I understand... if you want to save the file with the name of the file in the url, try this $filename = basename($url); file_put_contents($filename, $buffer); Be aware though that urls don't always have file names at the end. For example, this is a valid url and basename will return "?id=1" as the filename http://example.com/?id=1 Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200504 Share on other sites More sharing options...
TheSky Posted April 12, 2011 Author Share Posted April 12, 2011 perfect you got it thanks, and now is some way to just save as example like www.example.com just example ? Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200507 Share on other sites More sharing options...
spiderwell Posted April 12, 2011 Share Posted April 12, 2011 reg expres or explode Quote Link to comment https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/#findComment-1200514 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.