Jump to content

Simple code random error


Mudsaf
 Share

Recommended Posts

This messes whole page with no erros.

foreach ($file_allowed_extensions as $i => $file_allowed_extensions_value) {if ($fileupload == 0  || !isset($fileupload)) {if ($file_extension == $file_allowed_extensions_value) {$fileupload = 1;} else {$fileupload = 0;}}} foreach ($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {if ($thumbnailupload == 0 || !isset($thumbnailupload)) {$thumbnailupload = 1;} else {$thumbnailupload = 0;}}}

This doesnt

foreach ($file_allowed_extensions as $i => $file_allowed_extensions_value) {if ($fileupload == 0  || !isset($fileupload)) {if ($file_extension == $file_allowed_extensions_value) {$fileupload = 1;} else {$fileupload = 0;}}}foreach ($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {//if ($thumbnailupload == 0 || !isset($thumbnailupload)) {$thumbnailupload = 1;} else {$thumbnailupload = 0;}//}}

Seems like had problems with $thumbnailupload, changed it to $thumbupload and works.

Edited by Mudsaf
Link to comment
Share on other sites

So the problem is fixed now?A couple notes:First, you should indent your code. I can't read it. Something like this:

foreach($file_allowed_extensions as $i => $file_allowed_extensions_value) {	if ($fileupload == 0 || !isset($fileupload)) {		if ($file_extension == $file_allowed_extensions_value) {			$fileupload = 1;		} else {			$fileupload = 0;		}	}}foreach($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {	if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {		if ($thumbnailupload == 0 || !isset($thumbnailupload)) {			$thumbnailupload = 1;		} else {			$thumbnailupload = 0;		}	}}

Second, you can use ternary to shorten your code quite a bit. The following code does the same as above:

foreach($file_allowed_extensions as $i => $file_allowed_extensions_value) {	if ($fileupload == 0 || !isset($fileupload)) {		$fileupload = ($file_extension == $file_allowed_extensions_value) ? 1 : 0;	}}foreach($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {	if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {		$thumbnailupload = ($thumbnailupload == 0 || !isset($thumbnailupload)) ? 1 : 0;	}}

Link to comment
Share on other sites

So the problem is fixed now? A couple notes: First, you should indent your code. I can't read it. Something like this:
foreach($file_allowed_extensions as $i => $file_allowed_extensions_value) {	if ($fileupload == 0 || !isset($fileupload)) {		if ($file_extension == $file_allowed_extensions_value) {			$fileupload = 1;		} else {			$fileupload = 0;		}	}} foreach($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {	if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {		if ($thumbnailupload == 0 || !isset($thumbnailupload)) {			$thumbnailupload = 1;		} else {			$thumbnailupload = 0;		}	}}

Second, you can use ternary to shorten your code quite a bit. The following code does the same as above:

foreach($file_allowed_extensions as $i => $file_allowed_extensions_value) {	if ($fileupload == 0 || !isset($fileupload)) {		$fileupload = ($file_extension == $file_allowed_extensions_value) ? 1 : 0;	}} foreach($thumbnail_allowed_extensions as $i => $thumbnail_allowed_extensions_value) {	if ($thumbnail_extension == $thumbnail_allowed_extensions_value) {		$thumbnailupload = ($thumbnailupload == 0 || !isset($thumbnailupload)) ? 1 : 0;	}}

Yea i agree with identifying the code, but if i would ternary shorten my code i could not understand it as i do now.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...