tags:

views:

27

answers:

2

Yes i have this line in my first "upload" case of the switch:

$file_name = $USER . "-".rand(1, 888).".jpg";

Then in my switch case "crop" (that takes care of the image you crop), I wish to replace the uploaded one with the new one, simply by uploading with same name. Now i cant use $file_name in the case "crop" so how can I do this?

A: 

A switch is just a lot os IFs. Did you try with IFs?

eKek0
To the user who downvoted the answer, can explain why?
eKek0
@eKek0: possibly because the OP stated he was using `switch`/`case`
jnpcl
A: 
$file_name = "";

switch ($step_name)
{
    case "upload":
        $file_name = $USER . "-".rand(1, 888).".jpg";
        break;
    case "crop":
        //now you can use $file_name because the scope is outside of the switch statement
        break;
    default:
        break;
}

You would need to place $file_name in a different scope.

Evan Mulawski
so if i echo $file_name in case crop, it will output 1-888.jpg? (example)
Johnson
@user457827 - No it won't. Did you accept his answer before even checking if the code is correct?
mellowsoon
Like mellowsoon said, it won't. I do not have any clue what you are trying to accomplish by doing this. The best way is to create two separate php pages that do these completely different tasks, or just set $file_name when the php script begins and use it for the remainder of the script.
Evan Mulawski