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
Share on other sites

Looks like hitman got it :)  I would also recommend changing the error message to this:

 

echo "invalid file type: " . $_FILES['file']['type'];

[/code]

 

Or for debugging purposes, during script development only:

 

echo "invalid file<br>";
var_dump($_FILES);

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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