Jump to content

Archived

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

xyn

Upload problems...

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]

Share this post


Link to post
Share on other sites
How many threads on the subject are you going to open?

Share this post


Link to post
Share on other sites
:/ only this, the other was an old threat... besides that wasn't very helpful.

Share this post


Link to post
Share on other sites
[code=php:0]
if (!getimagesize($fileName)) {
  echo "not an image";
}
[/code]

Share this post


Link to post
Share on other sites
i get this error:
Warning: getimagesize(pm.PNG): failed to open stream: No such file or directory in /home/eumod/public_html/upload/upload.php on line 23

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.