/    Sign up×
Community /Pin to ProfileBookmark

creating and writing to files, inside a sub-folder

I know the solution is quite simple, but iv’e been working my brain for too long now.

I want PHP to create a folder, if it doen’t alredy exist.
that part works fine. than i want it to copy a file from one place to inside the created folder–thats where the errors are:

Warning: copy(/new_script/index2.php ): failed to open stream: No such file or directory in …/copy.php on line 26

line 26:
copy(‘http:// … files/’.$file,’/new_script/’.$file);
Yes, there really is somthing replaced by the ‘ … ‘
yes, fopen-wrapper is enabled.
I have tried it without the start slash for the 2nd property, too.

any help is good.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@PunkSktBrdr01Nov 26.2003 — You have a comma instead of a period after the first $file.
Copy linkTweet thisAlerts:
@diamondsauthorNov 26.2003 — basicly, the variables replaced with their values are

copy("http://SERVER/files/file1.txt","/new_script/index1.php")

I don't think you see there is a comma after the first $file

this is exactly how the text appears in the main post:

[SIZE=4]copy('http:// ... files/'.$file,'/new_script/'.$file);[/SIZE]
Copy linkTweet thisAlerts:
@diamondsauthorNov 27.2003 — ive narrowed it down to a totally [COLOR=deeppink]freak[/COLOR] variable bug.

[code=php]
copy($server.'files/'.$s.$ext,realpath('new_script'.'/index1.txt')); //totally works

copy($server.'files/'.$s.$ext,realpath('new_script'.$file)); //totally gives an error

echo $file;//prints '/index1.txt'
[/code]


the variable $file is equel to '/index1.php' and, using it, it gives an error. however , replacing it with its string equivelant, '/index1.txt', it works fine.

do you think this is a bug in PHP?
Copy linkTweet thisAlerts:
@PunkSktBrdr01Nov 28.2003 — Not sure if it would make a difference, but try adding the slash to the "new_script" part and removing the slash from the file name.
×

Success!

Help @diamonds 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.19,
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,
)...