views:

39

answers:

1

I'm building a php upload script for images, and it refuses to run at all.

First off, I've got a simple post form like this:

    <form action="variables.php" method="post" enctype="multipart/form-data" >  
  <p>Event title : <input type="text" name="name" required></p>
  <p>Description : <input type="text" name="description" required></p>
  <input type="file" name="file" id="file"/>
  <input type="submit" value="submit">
    </form>

This then feeds the submitted fields to "variables.php", which looks like this:

  <?php
 require("myfunctions.php");

 $title = $_POST['name'];
 $description =$_POST['description']; 
  $img = $_FILES["file"];

 imgput($img);
 generator($title, $description);
     ?>

"imgput" and "generator" are functions from "myfunctions.php", but the problem isn't in "genrator", so here's what "myfunctions.php" looks like:

    <?php
function imgput($img) { 
 if ((($img["type"] == "image/gif")
 || ($img["type"] == "image/jpeg")
 || ($img["type"] == "image/pjpeg"))
  && ($img["size"] < 500000))
   {
   if ($img["error"] > 0)
     {
     echo "Return Code: " . $img["error"] . "<br />";
     }
   else
     {
     echo "Upload: " .$img["name"] . "<br />";
     echo "Type: " . $img["type"] . "<br />";
     echo "Size: " . $img["size"] / 1024) . " Kb<br />";
     echo "Temp file: " . $img["tmp_name"] . "<br />";

     if (file_exists("../uploads/" . $img["name"]))
       {
       echo $img["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($img["tmp_name"],
       "../uploads/" . "event1.jpg");
       echo "Stored in: " . "../uploads/event1.jpg";
       }
     }
   }
 else
   {
   echo "Invalid file";
   }
}

?>

Any help would be great. I tried running test echos right after "imgput" begins, but it won't even run it.

A: 

You're missing a ( here:

echo "Size: " . $img["size"] / 1024) . " Kb<br />";
                                  ^^^  no matching ( available

Most likely you wanted this:

echo "Size: " . ($img["size"] / 1024) . " Kb<br />";

If you had error_reporting turned on, you'd have seen the syntax error:

PHP Parse error:  syntax error, unexpected ')', expecting ',' or ';' in /home/marc/test.php on line 16
Marc B
Thanks! And thanks for putting up with the screwed up formatting.
Ian