upload form file types....


Posted on 16th Feb 2014 07:03 pm by admin

Hey all, I am learning PHP and I am writing a script from the W3C Schools tutorials for uploading files to my server. I want to be able to use it for a friend to upload files to my server (I know to be careful). I only want it to be able to allow those images, exe, rar and zip files, no ISO's, .IMG's etc... I understand how the code works and have added and extra image file extension, but how would I add .exe, .zip and .rar? I thought maybe app/exe etc... and tried it, but I don't think it worked, files aren't being uploaded other than the images. All my permissions are set right and my test files sizes are ok.
What I am is asking is what is the code to allow those 3 file types to be uploaded?

Here is my code:
Code: <?php
if (((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg")))
&& ($_FILES["file"]["size"] < 8000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>

100 Like 10 Dislike
Previous php-forum Next php-forum
Other php-forum

Request-URI Too Large
I have created a simple submit form for a mysql database that puts a piece of code into database.<

PHP referral database. I would like this form to email the referrer.
Okay, Hello I've been trolling for years. This the first time I've ever asked for php help. Normally

PHP Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with

Wierd if else problem
Hi guys,

this probably aint wierd for you, but it seems like php is playin up to me. may b i

Creating an invoice
Using fpdf I am trying to create an invoice to send to clients. The products are sold in pricing tie

Mail Script Problems
I have created a PHP mail script. I am having a problem though. In $body i am trying to put two va

Create comparison matrix?
I want to create a comparison script for forum software and was wondering is there any tutorial or b

md5 is it unique
I know this is most likely one of many simple questions that can be found semi easily. But I'm press

Problem with an browser game.
Hello,i just joined that great forum and i got php prob,its kinda freaky...anyway i got browser game

reading xml faster than DB call?
I am trying to optimize a high traffic website, and I enabled a feature where there are three photos

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash