Jump to content

[SOLVED] Upload function not working....


aschulz90

Recommended Posts

Hi I have this function and it returns all the values correctly but I can't find it on the server or local machine ever, its annoying because it will return the size and location I want it to be, but its not there (the temporary file never seems to be there either). Where is the file actually being saved to? or where should it, why won't it save there? here's the code

function Uploader()
{
if (($_FILES["file"]["type"] == "application/msword") && ($_FILES["file"]["size"] < 100000))
  {
   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: " . "/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
}

Thanks for any help.

Link to comment
Share on other sites

you are telling it where to load the file, ignore ainoy.

 

one thing to check is what move_uploaded_file() is returning.  it will only jog an error if it wasn't moved for some unknown reason.  try this:

 

move_uploaded_file() or die('file could not be moved for some reason');

 

this will force a fail in the case that move_uploaded_file() returns FALSE, indicating a botched copy job.  an additional check that might help is using file_exists() AFTER trying to copy the file over.

Link to comment
Share on other sites

Add the following two lines after your first opening <?php tag to get php to tell you why the function is failing -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

My guess is that the move_uploaded_file() will generate an error about the /upload/ path not existing. The leading slash refers to the root of the current drive.

Link to comment
Share on other sites

Wow that makes me feel like a dumbass! (but really happy I can debug my code!) now here are the error I am getting:

 

Warning: move_uploaded_file(Tryit.doc) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Web Data\Inetpub\wwwroot\GOVERNMENT\Test.php on line 28

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\phpAB.tmp' to 'Tryit.doc' in C:\Web Data\Inetpub\wwwroot\GOVERNMENT\Test.php on line 28

file could not be moved for some reason

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.