Jump to content

Uploading Files


nepeaNMedia

Recommended Posts

Hi Folks

 

I have seen this question posted in a couple of places but none of the answers have sorted out my problem.

 

I have recently moved servers which also meant a new version of php, php 5.1.6.

 

The code below, worked on the previous server but not this new one, if anyone has time could they suggest where I might be going wrong. I ftp a file to the server and then try to load the same file and it recognises that the file exists therefore, the code recognises the upload file

 

Please help if you are able

 

///////the code/////

<body>

 

<?

define(ULDIR,'uploads/');

chmod(ULDIR, 0777);

 

//////////FOR RESPONSE

///////////////////////

if(isset($_POST['submit'])){

///////////////////////

 

 

if (($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg")

&& ($_FILES["file"]["size"] < 20000))

  {

  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(ULDIR . $_FILES["file"]["name"]))

 

 

  {

      echo $_FILES["file"]["name"] . " already exists. ";

      }

    else

      {

 

    move_uploaded_file($_FILES["file"]["tmp_name"], ULDIR . $_FILES["file"]["name"]);

 

  echo "Stored in: " . ULDIR . $_FILES["file"]["name"];

      }

    }

  }

else

  {

  echo "Invalid file";

  }

 

//////////FOR RESPONSE END

///////////////////////

}

///////////////////////

 

 

?>

 

<!--form-->

<form action="<? $_SERVER['PHP_SELF']; ?>" method="post"

enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file" />

<br />

<input type="submit" name="submit" value="Submit" />

</form>

 

</body>

 

/////end code

Link to comment
https://forums.phpfreaks.com/topic/80401-uploading-files/
Share on other sites

the above is needed if you are using a linux or unix server. if you are using dreamweaver you can view the files on the remote server, then right click the file and set permissions. Otherwise go to your control panel for the server and figure it out from there. It'd probably be in some sort of file manager.

Link to comment
https://forums.phpfreaks.com/topic/80401-uploading-files/#findComment-410741
Share on other sites

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.