+ Reply to Thread
Results 1 to 3 of 3

Thread: error uploading files with php

  1. #1
    stalkio is offline x10Hosting Member stalkio is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    45

    Question error uploading files with php

    Having a few problems with this script for an uploading file feature:

    PHP Code:
    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_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("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";
      }
    ?>
    I try to upload a jpg file of 42kb but it comes up with "invalid file" - can anyone see anything I can't? Stalks

  2. #2
    Nathan H is offline x10 Elder Nathan H is an unknown quantity at this point
    Join Date
    Apr 2006
    Posts
    562

    Re: error uploading files with php

    try adding this line to that starting IF
    || ($_FILES["file"]["type"] == "image/jpg")
    and check the headers are ok on the file you are uploading
    Nathan H Formerly UnFoundBug



    http://www.theadmin.co.uk - Yes i know the colours don't go, I'm working on it.

    VPS Admin | x10-commandments

    So thats where it went! I thought i was losing my mind.

  3. #3
    stalkio is offline x10Hosting Member stalkio is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    45

    Re: error uploading files with php

    It didn't quite work as I'd hoped. I did make some minor changes to the syntax removing some excess brackets but I'm still getting an 'invalid file' message. I have a directory called "upload" in the same location on the server so I'm definitely baffled with this one.

    Maybe I should add that this is how it now looks -


    PHP Code:
    <?php
    if (($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpg")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg")
    && (
    $_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("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";
      }
    ?>
    Last edited by stalkio; 08-30-2008 at 06:04 AM.

+ Reply to Thread

Similar Threads

  1. PHP files won't load
    By AlexLH in forum Free Hosting
    Replies: 6
    Last Post: 08-28-2008, 08:54 AM
  2. Cannot Access PHP Files
    By pasacom in forum Free Hosting
    Replies: 1
    Last Post: 03-18-2008, 09:58 PM
  3. PHP files just want to download
    By bugfinder in forum Free Hosting
    Replies: 14
    Last Post: 01-04-2008, 09:35 AM
  4. How to protect images without htaccess using PHP
    By frznmnky in forum Tutorials
    Replies: 0
    Last Post: 12-26-2007, 11:51 AM
  5. Including Files With PHP
    By sk1tL1L in forum Tutorials
    Replies: 6
    Last Post: 09-22-2006, 05:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers