Jump to content

how i add name of file


TheSky

Recommended Posts

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/233457-how-i-add-name-of-file/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

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