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
https://forums.phpfreaks.com/topic/117615-solved-upload-function-not-working/
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.

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.

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

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.