Jump to content

New Uploader Help


jwilh

Recommended Posts

I am following a tutorial create an uploader for my site but it is not working for some strange reason , it keeps saying file is invalid when i try to upload a small pic, and then when it does go through i cannot find it on my server.Here is the code for it:
[code]<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?>

<?php

if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 30000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }

?>

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 30000))
  {
  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("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/26109-new-uploader-help/
Share on other sites

try altering your if to this..

if (($_FILES["file"]["type"] == "image/gif"
|| $_FILES["file"]["type"] == "image/jpeg")
&& $_FILES["file"]["size"] < 30000)

Also make sure that your file input is called 'file' (sometimes the most obvious thing is overlooked ;))
Link to comment
https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119392
Share on other sites

Nm i figured that out and part of it worked, but then i got this.
[code]Warning: move_uploaded_file(upload/s###.jpg): failed to open stream: No such file or directory in /home/www/#######.com/php/upload_file.php on line 63

Warning: move_uploaded_file(): Unable to move '/tmp/phpQft5yL' to 'upload/###.jpg' in /home/www/########/php/upload_file.php on line 63
Stored in: upload/###.jpg[/code]
Link to comment
https://forums.phpfreaks.com/topic/26109-new-uploader-help/#findComment-119398
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.