Re: [PHP] very weird PHP behaviour...
try this: function Upload($source_file,$source_filename,$dest_dir,$allowed_types=array(), $upload_errmsg="") { if( count($allowed_types) ) { if(!in_array(ArquivoExt($source_filename),$allowed_types)) { ?>O arquivo não está entre os tipos autorizados To: <[EMAIL PROTECTED]> Sent: Wednesday, November 14, 2001 8:34 AM Subject: [PHP] very weird PHP behaviour... I don't know what it is... but PHP is acting very weird today... or I am becoming crazy... can anyone tell me which one? I have this function: function Upload($source_file,$source_filename,$dest_dir,$allowed_types=array()) { global $upload_errmsg; if( count($allowed_types) ) { $file_ext=ArquivoExt($source_filename); $ext_found=in_array($file_ext,$allowed_types); //die("source=$source_filename"); //var_dump($ext_found); //die; if( !$ext_found ) { $upload_errmsg="O arquivo \"$source_filename\" não está entre os tipos autorizados"; //die("errmsg=$upload_errmsg"); return false; } } ... some more code here .. return true; } the first crazy behaviour is... I use a test file called something.jpg, ArquivoExt() returns me the extension of a given filename, in this case "jpg". $allowed_types contains "gif","jpg" and "png" so that in_array() should return true... and it does... but get this... if I uncomment that var_dump() guess what it outputs? bool(true) bool(false) very weird... how can one var_dump() call gives me two outputs? This double output doesn't occur if I uncomment the "die" after the var_dump(). It only outputs bool(true) in that case. Now for the second weird behaviour... since no matter what, $ext_found will always be false (due to the previous weirdness) it will always enter the IF... but the weird thing is when the caller of Upload() prints $upload_errmsg it only outputs: O arquivo "" não está entre os tipos autorizados where is the filename? I've checked it tons of times... If I uncomment the second die, right after the $upload_errmsg assignment, it outputs ok, with the filename. Now, can someone explain me this VERY WEIRD behaviour?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] very weird PHP behaviour...
that's exactly the problem... damn, how couldn't I think of this.. I didn't realise that when a file is NOT uploaded its value is set to 'none'... and I was using empty() to check it... thanks a lot. At 10:54 14/11/01 -0600, Steve Cayford wrote: >Sure sounds like you're hitting this function twice by accident. Are you >sure you're only calling it once? That would explain why you only get one >output with the die(), but two without it. > >-Steve > >On Wednesday, November 14, 2001, at 10:34 AM, Christian Dechery wrote: > >>I don't know what it is... but PHP is acting very weird today... or I am >>becoming crazy... can anyone tell me which one? >> >>I have this function: >>function >>Upload($source_file,$source_filename,$dest_dir,$allowed_types=array()) >>{ >>global $upload_errmsg; >> >>if( count($allowed_types) ) >>{ >> $file_ext=ArquivoExt($source_filename); >> $ext_found=in_array($file_ext,$allowed_types); >> //die("source=$source_filename"); >> //var_dump($ext_found); >> //die; >> if( !$ext_found ) >> { >> $upload_errmsg="O arquivo \"$source_filename\" não está entre os >> tipos autorizados"; >> //die("errmsg=$upload_errmsg"); >> return false; >> } >>} >>... some more code here .. >>return true; >>} >> >>the first crazy behaviour is... I use a test file called something.jpg, >>ArquivoExt() returns me the extension of a given filename, in this case >>"jpg". $allowed_types contains "gif","jpg" and "png" so that in_array() >>should return true... and it does... but get this... if I uncomment that >>var_dump() guess what it outputs? >> >>bool(true) bool(false) >> >>very weird... how can one var_dump() call gives me two outputs? >>This double output doesn't occur if I uncomment the "die" after the >>var_dump(). It only outputs bool(true) in that case. >> >>Now for the second weird behaviour... since no matter what, $ext_found >>will always be false (due to the previous weirdness) it will always enter >>the IF... but the weird thing is when the caller of Upload() prints >>$upload_errmsg it only outputs: >> >>O arquivo "" não está entre os tipos autorizados >> >>where is the filename? I've checked it tons of times... If I uncomment >>the second die, right after the $upload_errmsg assignment, it outputs ok, >>with the filename. >> >>Now, can someone explain me this VERY WEIRD behaviour?? >> >> >> >>-- >>PHP General Mailing List (http://www.php.net/) >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >>To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] very weird PHP behaviour...
Sure sounds like you're hitting this function twice by accident. Are you sure you're only calling it once? That would explain why you only get one output with the die(), but two without it. -Steve On Wednesday, November 14, 2001, at 10:34 AM, Christian Dechery wrote: > I don't know what it is... but PHP is acting very weird today... or I > am becoming crazy... can anyone tell me which one? > > I have this function: > function > Upload($source_file,$source_filename,$dest_dir,$allowed_types=array()) > { > global $upload_errmsg; > > if( count($allowed_types) ) > { > $file_ext=ArquivoExt($source_filename); > $ext_found=in_array($file_ext,$allowed_types); > //die("source=$source_filename"); > //var_dump($ext_found); > //die; > if( !$ext_found ) > { > $upload_errmsg="O arquivo \"$source_filename\" não está entre os > tipos autorizados"; > //die("errmsg=$upload_errmsg"); > return false; > } > } > ... some more code here .. > return true; > } > > the first crazy behaviour is... I use a test file called something.jpg, > ArquivoExt() returns me the extension of a given filename, in this case > "jpg". $allowed_types contains "gif","jpg" and "png" so that in_array() > should return true... and it does... but get this... if I uncomment > that var_dump() guess what it outputs? > > bool(true) bool(false) > > very weird... how can one var_dump() call gives me two outputs? > This double output doesn't occur if I uncomment the "die" after the > var_dump(). It only outputs bool(true) in that case. > > Now for the second weird behaviour... since no matter what, $ext_found > will always be false (due to the previous weirdness) it will always > enter the IF... but the weird thing is when the caller of Upload() > prints $upload_errmsg it only outputs: > > O arquivo "" não está entre os tipos autorizados > > where is the filename? I've checked it tons of times... If I uncomment > the second die, right after the $upload_errmsg assignment, it outputs > ok, with the filename. > > Now, can someone explain me this VERY WEIRD behaviour?? > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] very weird PHP behaviour...
I don't know what it is... but PHP is acting very weird today... or I am becoming crazy... can anyone tell me which one? I have this function: function Upload($source_file,$source_filename,$dest_dir,$allowed_types=array()) { global $upload_errmsg; if( count($allowed_types) ) { $file_ext=ArquivoExt($source_filename); $ext_found=in_array($file_ext,$allowed_types); //die("source=$source_filename"); //var_dump($ext_found); //die; if( !$ext_found ) { $upload_errmsg="O arquivo \"$source_filename\" não está entre os tipos autorizados"; //die("errmsg=$upload_errmsg"); return false; } } ... some more code here .. return true; } the first crazy behaviour is... I use a test file called something.jpg, ArquivoExt() returns me the extension of a given filename, in this case "jpg". $allowed_types contains "gif","jpg" and "png" so that in_array() should return true... and it does... but get this... if I uncomment that var_dump() guess what it outputs? bool(true) bool(false) very weird... how can one var_dump() call gives me two outputs? This double output doesn't occur if I uncomment the "die" after the var_dump(). It only outputs bool(true) in that case. Now for the second weird behaviour... since no matter what, $ext_found will always be false (due to the previous weirdness) it will always enter the IF... but the weird thing is when the caller of Upload() prints $upload_errmsg it only outputs: O arquivo "" não está entre os tipos autorizados where is the filename? I've checked it tons of times... If I uncomment the second die, right after the $upload_errmsg assignment, it outputs ok, with the filename. Now, can someone explain me this VERY WEIRD behaviour?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]