PDA

View Full Version : Can someone explain this code to me:


Dimava
Thu 16th May '02, 6:26pm
function uploadProg($filename1,$filename1_name){ //function is called uploadProg which uses 2 variables
$destination="../images/newsimages"; //defines the location of the upload
copy($filename1,$destination."/".$filename1_name); //uploads the files
include("templates/uploaded.php"); //displayed "file uploaded successfully" screen
} //closes function

function main(){ //creates a blank function?
} //closes function

switch ($action){
default:
main();
break;
case "uploadProg":
if ($filename1=="none") {echo("<h1>No File Selected....</h1>"); break;}
uploadProg($filename1,$filename1_name);
break;
}


I've commented what i understand, but i'm lost on the other part


thanks,

-Dimava

Mark Hensler
Thu 16th May '02, 7:02pm
re-ordered it a tad bit to make it easier to read...

function uploadProg($filename1,$filename1_name) { // function is called uploadProg which uses 2 variables
$destination="../images/newsimages"; // defines the location of the upload
copy($filename1,$destination."/".$filename1_name); // copies uploaded file to $destination/$filename1_name
include("templates/uploaded.php"); // displayed "file uploaded successfully" screen
} // closes function

function main() { // creates a blank function?
} // closes function

switch ($action) { // what is the value of $action?
case "uploadProg": // $action == "uploadProg"
if ($filename1=="none") { // is a file selected?
echo("<h1>No File Selected....</h1>"); // nope
break; // break out of the switch
}
uploadProg($filename1,$filename1_name); // upload $filename1 to $filename1_name
break; // break out of the switch
default: // if $action != anything above
main(); // run main()
break; // break out of the switch
} // end switch

Dimava
Thu 16th May '02, 9:07pm
Ok thanks, but whats the blank function for...

Mark Hensler
Fri 17th May '02, 2:13am
I dont know, it does nothing.

Ben Box
Fri 24th May '02, 1:58pm
It doesnt do anything, so why have it? :confused:

Maybe its just to have more lines of code :p

Dimava
Fri 24th May '02, 5:23pm
actually I think its just because it needed something to point to if an error occurs

-Dimava

Dan615
Sat 25th May '02, 1:41am
The main function looks like it's there so the script has something to do when nothing matched the switch...case...thing. That would be the equivalent of "return 0" or "return" if that were inside a function.

I think.

Goldfinger
Sat 25th May '02, 11:46pm
Originally posted by Mark Hensler
re-ordered it a tad bit to make it easier to read...


switch ($action) { // what is the value of $action?


I do believe action would be called through the link in the browser. so the user can select what he wants to do .

Mark Hensler
Mon 27th May '02, 2:17am
lol....

That was my comment what the line does. It checks the value of $action.

see..

switch ($action) { // what is the value of $action?
case "uploadProg": // $action == "uploadProg"
//.......
default: // if $action != anything above
//.......
}

Goldfinger
Fri 31st May '02, 8:10pm
ahh .. lol i was tired. :/.