Jump to content

somethings wrong


nimirraj99

Recommended Posts

i'm new at this and i can't figure out why it isn't working. this is my PHP script

<html>

<body>

<?php

 

if (($_FILES["picture"]["type"] == "image/gif")

|| ($_FILES["picture"]["type"] == "image/pjpeg")

&& ($_FILES["picture"]["size"] < 20000))

  {

  if ($_FILES["picture"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["picture"]["error"] . "<br />";

    }

  else

    {

    echo "Upload: " . $_FILES["picture"]["name"] . "<br />";

    echo "Type: " . $_FILES["picture"]["type"] . "<br />";

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

    echo "Temp file: " . $_FILES["picture"]["tmp_name"] . "<br />";

echo $_POST ["picture"]

 

    if (file_exists("upload/" . $_FILES["picture"]["name"]))

      {

      echo $_FILES["picture"]["name"] . " already exists. ";

      }

    else

      {

      move_uploaded_file($_FILES["picture"]["tmp_name"],

      "upload/" . $_FILES["picture"]["name"]);

      echo "Stored in: " . "upload/" . $_FILES["picture"]["name"];

      }

    }

  }

else

  {

  echo "ERROR! Invalid file";

  }

 

 

?>

 

</body>

</html>

 

and this is what it should have done

 

    *  Saves the uploaded image into a specific directory.

    * Prints a confirmation message back to the user showing all the information received (date, time, title, etc) as well as information about the image file (type, size, name)

    * Your confirmation page should include the image itself (the actual picture, I mean).

    * Your confirmation page should also contain the "Back" button that brings to the input form.

    * In a case of failure you should print an error message.

    * Before moving the uploaded file from its temp location make sure that its size doesn't exceed 2 MB. If it does display an appropriate error message.

 

can someone help?

Link to comment
https://forums.phpfreaks.com/topic/49251-somethings-wrong/
Share on other sites

One issue that i see clearly is that you are not using "()" to join you "||" operators with your "&&" operator. Meaning according to your code file type must be image/pjpeg and its size must be < 2 mb only then this code will work, which you surely do not want. You also want image/gif files to be regarded by your code.

 

Try

 

if ( 
      (  ($_FILES["picture"]["type"] == "image/gif") || ($_FILES["picture"]["type"] == "image/pjpeg")     ) 
      && ($_FILES["picture"]["size"] < 20000)
   )

Link to comment
https://forums.phpfreaks.com/topic/49251-somethings-wrong/#findComment-241310
Share on other sites

i'm sorry i don't understand what you mean? do mean me or the code? me, i just got here and have only posted twice. my code, it is something i am working on for a class project so it is possible you have seen something similar. i just don't know what i'm doing really and just wondered if anyone could tell me what i might be doing wrong. honestly i'm pretty much lost on this stuff ???

Link to comment
https://forums.phpfreaks.com/topic/49251-somethings-wrong/#findComment-241313
Share on other sites

just reply honestly:

 

nimirraj99==oceans?

 

i see now why you say that. but we aren't the same person. like i said i don't know what i'm doing really so i've been looking at numerous tutorials and code sites for help. apparently this person was using the same one i was. and apparently they have no clue what they are doing either. honestly though i'm not the other person. i'm just nimirraj99.

 

 

 

and thanks to skali for the positive feedback!

Link to comment
https://forums.phpfreaks.com/topic/49251-somethings-wrong/#findComment-241324
Share on other sites

One issue that i see clearly is that you are not using "()" to join you "||" operators with your "&&" operator. Meaning according to your code file type must be image/pjpeg and its size must be < 2 mb only then this code will work, which you surely do not want. You also want image/gif files to be regarded by your code.

 

Try

 

if ( 
      (  ($_FILES["picture"]["type"] == "image/gif") || ($_FILES["picture"]["type"] == "image/pjpeg")     ) 
      && ($_FILES["picture"]["size"] < 20000)
   )

 

okay so if i'm thinking correctly if i do it like this

if (

      (  ($_FILES["picture"]["type"] == "image/gif" || $_FILES["picture"]["type"] == "image/jpeg")    )

      && ($_FILES["picture"]["size"] < 20000)

  )

 

...this will give me a check on file type "image/gif" or "image/jpeg" and a file size where they both (type and size) have to be returned true, is that right? (sorry if this seems silly but i really am having that much trouble)???

Link to comment
https://forums.phpfreaks.com/topic/49251-somethings-wrong/#findComment-241331
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.