Jump to content

File Uploads


ttomnmo

Recommended Posts

I am very new to this whole deals and was hoping to get some help. I used a script that I found online to do a very simple upload page, but it only works for gif files.

<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<?
if(isset( $Submit ))
{
if ($_FILES['imagefile']['type'] == "image/gif"){
       

copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
        }
else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
}
?> </form>

I was hoping that I could change the 

if ($_FILES['imagefile']['type'] == "image/gif"){   

line to some how copy any type of file.

Is this possible? And if so, how?

Thanks much!
Link to comment
Share on other sites

This is a very old script or one that is poorly designed. you need to make some changes so you protect your server. granted you are only allowing gif files, but anyone can upload any file type to your server and just call it some_file.gif. It's bad idea to use code that you don't understand, because your taking a chance that the person who coded this knows what they are doing, which in this case is not the case. There better examples in the PHP manual comments, I say that because most bad examples posted there are removed rather quickly!

I'll write you example, just me minute or two!

me!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.