toxictoad Posted December 12, 2008 Share Posted December 12, 2008 I have this code working if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />"; } else { echo "Sorry, there was a problem uploading your file."; } ?> What I don't get is how to take what's being echoed in the else statements and have it in the HTML code. Can anyone help? Thanks TT Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/ Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 <?php if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $uploadResult = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />"; } else { $uploadResult = "Sorry, there was a problem uploading your file."; } ?> Then in your html put <?php echo $uplaodResult; ?> where ever you want it Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713908 Share on other sites More sharing options...
mmarif4u Posted December 12, 2008 Share Posted December 12, 2008 Exactly like that. You won gevans. Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713910 Share on other sites More sharing options...
toxictoad Posted December 12, 2008 Author Share Posted December 12, 2008 thanks guys, I was playing with it and figured it out, I did it a little different though $success="The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br /><br />"; $error= "Sorry, there was a problem uploading your file."; then use <?=$success?><?=$error?> in the HTML code but your use of just $uploadResult will just mean that I only need to add <?=$uploadResult?> so thanks Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713920 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 this is an old way of doing things <?=$success?> please use <?php echo $success; ?> Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713922 Share on other sites More sharing options...
toxictoad Posted December 12, 2008 Author Share Posted December 12, 2008 this is an old way of doing things <?=$success?> please use <?php echo $success; ?> Ok thank's, picking it up as I go Before I mark it as solved would there be a way of adding a different graphic to each of these statements? Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713926 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 $error= "<div>Sorry, there was a problem uploading your file.</div><div><img src=\"yourimage.jpg\" alt=\"\" /></div>"; Just shove your html in there!! and dont forget to escape your quotes (if needed) Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713928 Share on other sites More sharing options...
mmarif4u Posted December 12, 2008 Share Posted December 12, 2008 this is an old way of doing things <?=$success?> please use <?php echo $success; ?> Yeh, its an old way. you can do this now also. but have to configure you php.ini file. Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713935 Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 @mmarif4u it can be done, but is not recommended Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713946 Share on other sites More sharing options...
mmarif4u Posted December 12, 2008 Share Posted December 12, 2008 @mmarif4u it can be done, but is not recommended You are right, not recommended. it was until php4. Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713949 Share on other sites More sharing options...
toxictoad Posted December 12, 2008 Author Share Posted December 12, 2008 Thanks gevans I'm slowly picking up the basics both <?=$success?> and <?php echo $success; ?> work so guess the server's setup ok, I'll stick to <?php echo $success; ?> Thanks again Link to comment https://forums.phpfreaks.com/topic/136712-solved-how-to-use-whats-echoed-in-an-else-statenements-in-the-html/#findComment-713950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.