/    Sign up×
Community /Pin to ProfileBookmark

rename() function for a file

Hi

I am running this script I found which works fine.

I use it to create a temporary file which I rename to have the pdf extension.

This is the code:

[COLOR=”Lime”]//Determine a temporary file name in the current directory[/COLOR]
[COLOR=”red”]$file = basename(tempnam(‘.’, ‘tmp’));
rename($file, $file.’.pdf’);
$file .= ‘.pdf’[/COLOR]
;
[COLOR=”lime”]//Save PDF to file[/COLOR]
[COLOR=”red”]$pdf->Output($file, ‘F’);[/COLOR]
[COLOR=”lime”]//Redirect[/COLOR]
[COLOR=”red”]header(‘Location: ‘.$file);[/COLOR]

As I said it works fine but the final name of the file is something like:

[COLOR=”Red”]tmp40C2.tmp.pdf[/COLOR]

I was wondering how this is possible if I first rename it and then add the string ‘.pdf’ to the file name.

Following the code, should not be something like this? :

[COLOR=”red”]tmp40C2.tmp.pdf.pdf [/COLOR]

Thanks!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachJul 19.2010 — You are making a logical thinking error here.

You have the file name in $file. Then you rename the file and add .pdf to the end. But you actually don't change the value of $file. That is why you still need to add the .pdf at the end manually.

Hope I could explain properly
×

Success!

Help @giovanni_85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...