Jump to content

File Upload


fruzzgle

Recommended Posts

Well, I'm having trouble with a file upload page. I just started really learning php today after many failed attempts to in the past. I'm using the w3schools tutorial to php, I already know xhtml, css, and a decent amount of javascript.

 

http://groogstestpages.freehostia.com/upload.php

Here is my failed upload test

 

upload.php

<html>
<head>
<title>
Upload Test
</title>
<link href="upload.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
  <form action="upload_file.php" method="post" encypte="multipart/form-data">
    <label for="file">File:</label>
    <input type="file" name="file" id="file">
    <input type="submit" name="submit" value="Upload">
  </form>
</div>
</body>
</html>

 

upload_file.php

<html>
<head>
<title>
Upload Test Complete
</title>
<link href="upload.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
  <?php
    if (($_FILES['file']['type'] == "image/gif")
    || ($_FILES['file']['type'] == "image/pjpeg"))
    {
      if ($_FILES['file']['error'] > 0){
        echo "Error" . $_FILES['file']['error'] . "<br />";
      }
      else
      {
        echo "Name: " . $_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 />";
        move_uploaded_file($_FILE['file']['tmp-name'], "upload/" . $_FILES['file']['name']);
        echo "stored in: " . "upload/" . $_FILES['file']['name'];
      }
    }
    else
    {
      echo "invalid file";
    }
  ?>
</div>
</body>
</html>

 

I followed the tutorial like w3schools said, and I'm not the kind that copies and pastes code, I took an hour to write and understand this script. Seeing it's telling me it's an invalid file I'm thinking that means it has something to do with the beginning of the script-

 

if (($_FILES['file']['type'] == "image/gif")
    || ($_FILES['file']['type'] == "image/pjpeg"))

 

http://www.w3schools.com/php/php_file_upload.asp

This is the w3 tutorial. I've taken out some of the script I didn't really want in there (like the size limit on files one)

Link to comment
https://forums.phpfreaks.com/topic/61959-file-upload/
Share on other sites

I don't know if your going to get really made because I double post but-

 

I changed the upload.php file and fixed the spelling error. I also made the folder name the same as the one in the script and added the thing to the error message. it still didn't work and the error message didn't display the type.

 

Edit:

 

invalid file

array(0) { }

 

What? I didn't use arrays!

Link to comment
https://forums.phpfreaks.com/topic/61959-file-upload/#findComment-308548
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.