/    Sign up×
Community /Pin to ProfileBookmark

Is this logic bad or what?

I have this short script that should create a directory if one does not exists in that path. then check if a file is in the newly created path, if it is then rename the file with the newName but it seems to create a new file regardless. here is the script.

[code=php]$img_name = $campaign_builder->LogoUpload->GetValue();
$campaign_name = $_SESSION[‘campaign_name’];//name of the new dir
$img_newname = $campaign_name . “_” . $campaign_builder->LogoUpload->GetFileName();//new file
global $COMPANY_LOGOS; //path to current directory where i want thenew folder created “/opt/logos/”
$company_logo_dir =$COMPANY_LOGOS;
$dirRoot = $company_logo_dir . $campaign_name;
if(!file_exists($dirRoot)){
//$company_logo_dir= @
$dirRoot= @mkdir($dirRoot);
}else{
$init_File= $dirRoot.’/’.$img_name;//
if(file_exists ($init_File)){//check if the file $img_name is already here
rename($dirRoot . $img_name, $dirRoot . $img_newname);//lets assume the path to logo ends with a slash/
}
else {
fopen($init_Logo, ‘w’);//will this create the file in the new directory
}
}[/code]

Also, how do i put the $img_newname in the new dir?

Help please

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ca87authorDec 04.2010 — I have this short script that should create a directory if one does not exists in that path. then check if a file is in the newly created path, if it is then rename the file with the newName but it seems to create a new file regardless. here is the script.[code=php]$img_name = $campaign_builder->LogoUpload->GetValue();
$campaign_name = $_SESSION['campaign_name'];//name of the new dir
$img_newname = $campaign_name . "_" . $campaign_builder->LogoUpload->GetFileName();//new file
global $COMPANY_LOGOS; //path to current directory where i want thenew folder created "/opt/logos/"
$company_logo_dir =$COMPANY_LOGOS;
$dirRoot = $company_logo_dir . $campaign_name;
if(!file_exists($dirRoot)){
//$company_logo_dir= @
$dirRoot= @mkdir($dirRoot);
}else{
$init_File= $dirRoot.'/'.$img_name;//
if(file_exists ($init_File)){//check if the file $img_name is already here
rename($dirRoot . $img_name, $dirRoot . $img_newname);//lets assume the path to logo ends with a slash/
}
else {
fopen($init_Logo, 'w');//will this create the file in the new directory
}
}[/code]

Also, how do i put the $img_newname in the new dir?

Help please[/QUOTE]



I figured out what was wrong.
×

Success!

Help @ca87 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.20,
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,
)...