Jump to content

[SOLVED] Help with upload script..


CrazeD

Recommended Posts

I'm working on an image gallery. I've never done this sort of thing before with uploads and whatnot, so I'm working the bugs out of my upload script. I can't seem to make it upload a .jpeg extension. What gives?

 

<?php
if (isset ($_POST['submit'])) {
if ($_FILES['file']['type'] == "image/gif") {
$type = ".gif";
} elseif ($_FILES['file']['type'] == "image/jpeg") {
$type = ".jpg";
}
$rand = rand(1,10000000);
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/djpeg")
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("uploads/".$rand."" . $_FILES["name"]))
      {
      echo $_FILES['file']["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      'uploads/'.$rand.''.$type.'');
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  print '<p>'.$type.'</p>';
      }
    }
  }
else
  {
  echo "Invalid file";
  }

} else {


?>


<form action="gallery.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="file" /><br />
<input type="submit" name="submit" value="Upload" />
</form>

<?php

}

?>

Link to comment
https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/
Share on other sites

Archived

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

×
×
  • 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.