Jump to content

Upload problems...


xyn

Recommended Posts

Hey,
I have got a small problem but It's fatal.
the problem is When I want images only
to be uploaded, I ewanted to set the file
type to image/Extention.

Yet when I try my way it doesn't work :/
can someone help me please.

-Ash

My code:
[code=php:0]<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

if($fileType != "image/gif" || $fileType != "image/jpg" || $fileType != "image/png" || $fileType != "image/tiff" || $fileType != "image/bmp")
{
die('<div align="center">
  <center>
  <table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#39638C" width="441" bgcolor="#AAD2FF">
    <tr>
      <td width="100%" bgcolor="#39638C" height="10"><b>
      <font face="Verdana" size="1" color="#AAD2FF">Upload has failed...</font></b></td>
    </tr>
    <tr>
      <td width="100%"><font face="Verdana" size="1">Sorry but the file you are
      trying to upload is not supported by our hosting, we only host images
      which are:<br>
      - JPG<br>
      - GIF<br>
      - PNG<br>
      - BMP<br>
      - TIFF<br>
      If you feel the image you are uploading should be supported please contact
      us <a href="help.php?action=contact&method=email">here</a>.</font></td>
    </tr>
  </table>
  </center>
</div>');
}

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

include 'db/db.php';
$date = date("d-m-y");
$time = $date("g:ia");
$ip = getenv('REMOTE_ADDR');

$query = "INSERT INTO upload (name, size, type, content, date, time, ip ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$date', '$time', '$ip')";

mysql_query($query) or die('Error, query failed');

echo '<div align="center">
  <center>
  <table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#39638C" width="441" bgcolor="#AAD2FF">
    <tr>
      <td width="100%" bgcolor="#39638C" height="10"><b>
      <font face="Verdana" size="1" color="#AAD2FF">'.$fileName.' Has been uploaded...</font></b></td>
    </tr>
    <tr>
      <td width="100%"><font face="Verdana" size="1">Thank you for using Eumod
      Image hosting, Your image was uploaded successfully, you can use this
      image in HTML and BB Code. Please click the preferred code below:<br>
&nbsp;</font><table border="0" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111" width="100%">
        <tr>
          <td width="20%" height="20"><b><font size="1" face="Verdana">BB Code:</font></b></td>
          <td width="80%" height="20">
          <input type="text" name="bbcode" size="43" style="font-family: Verdana; font-size: 8pt; border: 1px solid #39638C"></td>
        </tr>
        <tr>
          <td width="20%" height="20"><b><font size="1" face="Verdana">HTML:</font></b></td>
          <td width="80%" height="20">
          <input type="text" name="html" size="43" style="font-family: Verdana; font-size: 8pt; border: 1px solid #39638C"></td>
        </tr>
      </table>
      </td>
    </tr>
  </table>
  </center>
</div>';
}
else
{
die('<div align="center">
  <center>
  <table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#39638C" width="441" bgcolor="#AAD2FF">
    <tr>
      <td width="100%" bgcolor="#39638C" height="10"><b>
      <font face="Verdana" size="1" color="#AAD2FF">Upload has failed...</font></b></td>
    </tr>
    <tr>
      <td width="100%"><font face="Verdana" size="1">Sorry but you have not
      added a file which you wish to be hosted by Eumod image host.</font></td>
    </tr>
  </table>
  </center>
</div>');
}
?>[/code]
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.