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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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