Jump to content


Photo

Upload problems...


  • Please log in to reply
4 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 31 July 2006 - 10:23 PM

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:
<?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>');
}
?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 July 2006 - 10:33 PM

How many threads on the subject are you going to open?

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 31 July 2006 - 10:36 PM

:/ only this, the other was an old threat... besides that wasn't very helpful.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 31 July 2006 - 10:38 PM

if (!getimagesize($fileName)) {
  echo "not an image";
}


#5 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 01 August 2006 - 08:13 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users