Jump to content


Photo

Not allowing particular file extensions


  • Please log in to reply
6 replies to this topic

#1 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 26 April 2006 - 11:28 PM

Alright this is a really basic question but give me a little slack, its my 2nd day working with php :P

Here is the code I'm using:

<?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>

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!
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 26 April 2006 - 11:32 PM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 26 April 2006 - 11:52 PM

[!--quoteo(post=369067:date=Apr 26 2006, 07:32 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Apr 26 2006, 07:32 PM) View Post[/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 code

Also, is there a php function that will echo the directory of the php file?
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#4 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 27 April 2006 - 02:17 AM

I tried

if ($file_type == "image/jpg" or "image/png" or "image/gif")
{

but that didn't work. Any ideas!?
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#5 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 27 April 2006 - 03:37 PM

I'm pretty desperate here as I am new and just learning :'(
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 April 2006 - 04:59 PM

Your if statement should be this:
if ($file_type == "image/jpg" || $file_type == "image/png" || $file_type == "image/gif")


#7 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 27 April 2006 - 07:00 PM

Ah alright let me try that one out

EDIT:Yup that did it, thank you very much!

MERGED BY WILDTEEN88: PLEASE USE THE EDIT BUTTON RATHER THAN DOUBLE POSTING
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users