Jump to content

Archived

This topic is now archived and is closed to further replies.

smc

Not allowing particular file extensions

Recommended Posts

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:

[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!

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
[!--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 code

Also, is there a php function that will echo the directory of the php file?

Share this post


Link to post
Share on other sites
I tried

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

but that didn't work. Any ideas!?

Share this post


Link to post
Share on other sites
I'm pretty desperate here as I am new and just learning :'(

Share this post


Link to post
Share on other sites
Your if statement should be this:
[code]if ($file_type == "image/jpg" || $file_type == "image/png" || $file_type == "image/gif")[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.