Question

Hi I read all of topics with this title, but I didnt find solution.

Since my "web" is now online, not just localhost, file uploading doesnt work, before it was just fine.

Now the code:

move_uploaded_file($_FILES["file"]["tmp_name"],"/epoproject.hys.cz/web/directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]["name"]);

Tried this was or just:

move_uploaded_file($_FILES["file"]["tmp_name"],/epoproject.hys.cz/web/directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]["name"]);

Still nothing, CHMOD is set on 777.

  <?php session_start();
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  ?>
  .
  .some html code and variables
  .
  if ((($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/jpg")
    and other extensions...
  && in_array($extension, $allowedExts))
  {
   if ($_FILES["file"]["error"] > 0)
    {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
    else
   {
     if (file_exists("/directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]               ["name"]))
  {
  echo $_FILES["file"]["name"] . " již existuje. <br></br>";
  echo "<a href='upload.php'> Nahrát další soubor </a>";
  }
  else
  {
      echo "Soubor: <b>". $_FILES["file"]["name"] . "</b> byl úspěšně uploadován <br></br>";
      echo "Velikost souboru: " . ($_FILES["file"]["size"] / 1024) . " kB";
      echo "<br></br>";
      echo "<br></br>";
      echo "<a href='upload.php'> Nahrát další soubor </a>";
 move_uploaded_file($_FILES["file"]["tmp_name"],"/epoproject.hys.cz/web/directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]["name"]);
 $absolute_path = realpath("/directory/".$katedra."/".$predmet."/".$typ."/". $_FILES["file"]["name"]);
etc...
Was it helpful?

Solution

I made some changes, especially in the path.Try:

if ((($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/jpg")
  && in_array($extension, $allowedExts))){

    if ($_FILES["file"]["error"] > 0){
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
    else{
        if (file_exists("/directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]["name"])){
            echo $_FILES["file"]["name"] . " již existuje. <br></br>";
            echo "<a href='upload.php'> Nahrát další soubor </a>";
        }
        else{
            echo "Soubor: <b>". $_FILES["file"]["name"] . "</b> byl úspěšně uploadován <br></br>";
            echo "Velikost souboru: " . ($_FILES["file"]["size"] / 1024) . " kB";
            echo "<br></br>";
            echo "<br></br>";
            echo "<a href='upload.php'> Nahrát další soubor </a>";
            $path_image = "./directory/".$katedra."/".$predmet."/".$typ."/" . $_FILES["file"]["name"];
            if(move_uploaded_file($_FILES["file"]["tmp_name"], $path_image)){
                echo 'image file upload sucess';
            } else{
                echo 'image file upload failed';
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top