Write variables into fwrite

Hey there,

I am doing an fwrite to make an index.php page, its creating it just fine. But it isn’t putting in the variables.

[php]$exist = “…/files/$rar/index.php”;
$exist_handle = fopen($exist, ‘w’) or die(“can’t open file”);
$download_page = “<?php
$link = $uploadedfilename;
header(‘Content-Disposition: attachment; filename=’.basename($link).’’);
readfile($link);
exit();
?>”;
fwrite($exist_handle, $download_page);
fclose($exist_handle);
[/php]

It writes the page but this is what it turns out like:

[php]= ;
header(‘Content-Disposition: attachment; filename=’.basename().’’);
readfile();
exit();[/php]

Ideally I would it to write the index page to look like this:

[php]
$link = “mypicture.jpg” ;
header(‘Content-Disposition: attachment; filename=’.basename($link).’’);
readfile($link);
exit();[/php]

mypicture.jpg obviously being a variable written from the page that created the index.php page.

Thanks in advance!
James

This type of php code generation really doesnt make sense.

  1. Web is multi-user, so first person to hit this generator. creates a download link. If that person tries to download, 2nd person who hits this page, creates a new file which renders the 1st users link useless.

Only time I generate a php file is when it will be static.
I used this code here to grab files from another directory not in the webroot. (This was an example, so it’s very simple)

<?php $ipath='D:\Downloads\Images\\'; $img=isset($_GET['img'])?(basename($_GET['img'])):''; $info=pathinfo($img); if(empty($img) || !file_exists($ipath.$img) || $info['extension']!='jpg') { header("HTTP/1.0 404 Not Found"); die(); } header('Content-Type: image/jpg'); readfile($ipath.$img) ?>

It won’t override the original index.php page because it actually puts into a directory which is created randomly and defined as $rar.

Well than you should ecape non variable replacements in your string
example

$link = $uploadedfilename;

should be more like

\$link = '$uploadedfilename';

Thanks :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service