Jump to content


Photo

Uploading Images Problem


  • Please log in to reply
2 replies to this topic

#1 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 13 March 2006 - 01:52 AM

hello,

I have this script which allows users to upload files. I get the following error:

Parse error: syntax error, unexpected ',' in /home/cortez/public_html/testscripts/photoalbums/upload.php on line 2

All i want to do is to be able to have more than just .gif images available for upload. I want jpg, and bmp, etc.

here is the code for upload.html

<html>
<head>
<title>Upload now!</title>
</head>

<form action="upload.php" method="post" enctype="multipart/form-data">
  <p>File Upload</p>
  <label for="file">File</label>
  <input type="file" name="file" id="file" /> 
  <br />
  <input type="submit" name="submit" value="Submit" />

</form>
<body bgcolor="#FFFFFF">

</body>


</html>

and the code for upload.php


<?php
if (($_FILES["file"]["type"] == "image/gif", "images/jpg") &&
($_FILES["file"]["size"] < 150000)) {
  echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  echo "Uploading " . $_FILES["file"]["name"];
  echo " (" . $_FILES["file"]["type"] . ", ";
  echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />";

  if (file_exists("uploads/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists.  ";
    echo "Please delete the destination file and try again.";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"], 
    "uploads/" . $_FILES["file"]["name"]);
    echo "File has been stored in your uploads directory.";
  }

} else
  echo "Sorry, we only accept .GIF images under 15Kb for upload.";
?> 

help would be greatly appreciated. Thanks.

HoTDaWg

Handy links:
Google
PHP Manual


#2 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 13 March 2006 - 01:57 AM

Try


<?php
if (($_FILES["file"]["type"] == "image/gif" OR "images/jpg") &&
($_FILES["file"]["size"] < 150000)) {
  echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  echo "Uploading " . $_FILES["file"]["name"];
  echo " (" . $_FILES["file"]["type"] . ", ";
  echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />";

  if (file_exists("uploads/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists.  ";
    echo "Please delete the destination file and try again.";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "uploads/" . $_FILES["file"]["name"]);
    echo "File has been stored in your uploads directory.";
  }

} else
  echo "Sorry, we only accept .GIF images under 15Kb for upload.";
?>


#3 HoTDaWg

HoTDaWg
  • Members
  • PipPipPip
  • Advanced Member
  • 275 posts
  • LocationToronto

Posted 13 March 2006 - 02:11 AM

thanks a lot dude. Btw, LP and FM RULES! W00T!

Handy links:
Google
PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users