smc Posted April 26, 2006 Share Posted April 26, 2006 Alright this is a really basic question but give me a little slack, its my 2nd day working with php :PHere is the code I'm using:[code]<?php$formurl = "/uploaded/";$linkurl = "/uploaded/$file_name";if($file_name !=""){copy ("$file", "./uploaded/$file_name") or die("Could not copy file");}else { die("No file specified");}?><html><head><title>Project Cold Fusion Upload Centre :: Upload Complete</title></head><body><h3>File upload succeeded...</h3><ul><li>Sent: <?php echo "$file_name"; ?><li>Size: <?php echo "$file_size"; ?> bytes<li>Type: <?php echo "$file_type"; ?></ul><a href="<?php echo "$linkurl" ?>">Click here to view your file</a></br><b>File Address:</b> <a href="<?php echo "$linkurl" ?>"><?php echo "$linkurl" ?></a></body></html>[/code]I want to be able to have something saying if file extension is equal to like, for example, mp3, exe, etc. then it won't allow it and will echo the message "Invalid file extension".Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/ Share on other sites More sharing options...
litebearer Posted April 26, 2006 Share Posted April 26, 2006 Check this tutorial on this forum[a href=\"http://www.phpfreaks.com/tutorials/36/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/36/0.php[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31166 Share on other sites More sharing options...
smc Posted April 26, 2006 Author Share Posted April 26, 2006 [!--quoteo(post=369067:date=Apr 26 2006, 07:32 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Apr 26 2006, 07:32 PM) [snapback]369067[/snapback][/div][div class=\'quotemain\'][!--quotec--]Check this tutorial on this forum[a href=\"http://www.phpfreaks.com/tutorials/36/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/36/0.php[/a]Lite...[/quote]Being new to PHP, I am not entirley sure how to incorporate that into my codeAlso, is there a php function that will echo the directory of the php file? Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31170 Share on other sites More sharing options...
smc Posted April 27, 2006 Author Share Posted April 27, 2006 I tried [code]if ($file_type == "image/jpg" or "image/png" or "image/gif"){[/code]but that didn't work. Any ideas!? Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31183 Share on other sites More sharing options...
smc Posted April 27, 2006 Author Share Posted April 27, 2006 I'm pretty desperate here as I am new and just learning :'( Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31356 Share on other sites More sharing options...
wildteen88 Posted April 27, 2006 Share Posted April 27, 2006 Your if statement should be this:[code]if ($file_type == "image/jpg" || $file_type == "image/png" || $file_type == "image/gif")[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31376 Share on other sites More sharing options...
smc Posted April 27, 2006 Author Share Posted April 27, 2006 Ah alright let me try that one out[b]EDIT:[/b]Yup that did it, thank you very much![b]MERGED BY WILDTEEN88: PLEASE USE THE EDIT BUTTON RATHER THAN DOUBLE POSTING[/b] Quote Link to comment https://forums.phpfreaks.com/topic/8511-not-allowing-particular-file-extensions/#findComment-31412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.