Jump to content

Recommended Posts

We had a comprehensive uploading feature based on PHP for our website, but since we recently changed servers it seems to be giving us problems.

 

I've looked into the permission settings, etc and everything seems intact, but i am still not able to upload files.

 

Not sure if posting code will necessarily make a difference, but I can if needed. Has anyone had similar issues, or aware of what might be the cause?

 

Any insight would be greatly appreciated  8)

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

I created a test case which has the following code:

 

[pre]

<?php

$host="****"; // Host name

$username="****"; // Mysql username

$password="****"; // Mysql password

$db_name="****"; // Database name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

//upload file

$target = "images/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

$filename = "./".basename( $_FILES['uploaded']['name']) ;

 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))

{

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

}

else {

echo "Sorry, there was a problem uploading your file.";

}

 

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Upload TEST</title>

</head>

 

<body>

<br/> test...

</body>

[/pre]

 

and it gives the "sorry there was a problem uploading your file" message...

 

i tried displaying a table from my db on the page and it works fine but i can't seem to upload onto my ftp.

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352361
Share on other sites

Yep. I just have a simple form setup that passes through the data to this page...

 

The body of that page contains:

<p> <form enctype="multipart/form-data" action="upload2.php" method="POST">

          File:

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

          <input type="submit" value="Upload" />

        </form></p>

 

Thanks 8)

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352395
Share on other sites

Try something really simple at first, like this:

 

<?php

// Check the error code
if ($_FILES['uploaded']['error'] == 0)
{
   // Just use the file name and save in the current location
   $target = basename($_FILES['uploaded']['name']);
   if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
   {
      echo "File moved OK";
   }
   else
   {
      echo "Couldn't move file";
   }   
}
else
{
   echo "There was an error uploading the file";
}

 

Regards

Huggie

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352411
Share on other sites

Try this then...

 

<?php

// Check the error code
if ($_FILES['uploaded']['error'] == 0)
{
   // Is the current directory writable
   if (is_writable(dirname(__FILE__)))
   {
      // Just use the file name and save in the current location
      $target = basename($_FILES['uploaded']['name']);
      echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target;
      if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
      {
         echo "File moved OK";
      }
      else
      {
         echo "Couldn't move file";
      }   
   }
   else
   {
      echo "Directory isn't writable";
   }
else
{
   echo "There was an error uploading the file";
}
?>

 

Regards

Huggie

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352420
Share on other sites

Sorry,

 

Missed off a closing bracket.  Try this (tested and working)...

 

<?php

// Check the error code
if ($_FILES['uploaded']['error'] == 0)
{
   // Is the current directory writable
   if (is_writable(dirname(__FILE__)))
   {
      // Just use the file name and save in the current location
      $target = basename($_FILES['uploaded']['name']);
      echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target;
      if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
      {
         echo "File moved OK";
      }
      else
      {
         echo "Couldn't move file";
      }
   }
   else
   {
      echo "Directory isn't writable";
   }
}
else
{
   echo "There was an error uploading the file";
}
?>

 

Regards

Huggie

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352443
Share on other sites

change

      $target = basename($_FILES['uploaded']['name']);
      echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target;
      if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))

 

to

      $target = basename($_FILES['uploaded']['name']);
      $targetpath = "uploads/"; //<---set this to the upload PATH, make sure is writeable
      $target = $targetpath.$target;

      echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target;
      if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))

Link to comment
https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352628
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.