Jump to content


Photo

Problem with Uploading


  • Please log in to reply
2 replies to this topic

#1 jvo

jvo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 April 2006 - 05:35 AM

Okay, so I've been trying to figure this out for a while. I've rewritten the code and checked for simple syntax error and I still get the same result. There's no error, but it just doesn't do anything. I've put an echo statement in there to test that the parameter has been set, but it obviously hasn't. Can anyone tell me why that is?

Here's my code. It's a little primative, but I've not done any fine tuning. I just want to get it to do one thing first. Eventually, I want to have the URLs of the files to be saved to a DB, but as I've not yet gotten this to work, I haven't written it.

<html>
<head>
<title> .::Upload::. </title>
</head>


<body>

<?php
if(isset($_POST['upload1'])){
   echo "Word Up";
   //Upload path (relative to this file)
   $uploadDir = "images/";
   $path1 = $uploadDir . basename($_FILES['upload1']['name']);
      echo "Word Up";
   if(move_uploaded_file($_FILES['upload1']['tmp_name'],$path1)){
      echo "The file ". basename($_FILES['upload1']['name'])." has been sucessfully uploaded";
      }
   else{
      echo "There was an error with your upload. Please try again.";
      }

   if(isset($_POST['upload2'])){
         $path2 = $uploadDir . basename($_FILES['upload2']['name']);

      if(move_uploaded_file($_FILES['upload2']['tmp_name'],$path2)){
         echo "The file ". basename($_FILES['upload2']['name'])." has been successfully uploaded";
         }
      else{
         echo "There was an error with your upload. Please try again.";
         }
      }

   if(isset($_POST['upload3'])){
         $path3 = $uploadDir . basename($_FILES['upload3']['name']);

      if(move_uploaded_file($_FILES['upload3']['tmp_name'], $path3)){
         echo "The file ". basename($_FILES['upload3']['name'])." has been successfully uploaded";
         }
      else{
         echo "There was an error with your upload. Please try again.";
         }
      }

   }


?>

<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="650000">
<font face="arial" pt size="2">
File location: <input type="file" name="upload1">
<br>
File location: <input type="file" name="upload2">
<br>
File location: <input type="file" name="upload3">
<br>
<input type="submit" value="Upload">
</form>

</body>
</html>

I'm trying to check that the value of atleast the first file has been set with if (isset($_POST['upload1'])) {... but I'm guessing it's returning false and I don't know why. Can anyone shead some light on this?

#2 jvo

jvo
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 25 April 2006 - 04:04 PM

//bump

#3 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 25 April 2006 - 04:16 PM

Try it.. =)

D.Soul

<?php
if ( isset( $_POST['MAX_FILE_SIZE'] ))
{
    $uploadDir = 'images/';
    // Upload 1
    if ( $HTTP_POST_FILES['upload1']['error'] == 0 ) 
    {
        $path1 = $uploadDir . basename( $HTTP_POST_FILES['upload1']['name'] );
        if ( move_uploaded_file ( $HTTP_POST_FILES['upload1']['tmp_name'] , $path1 ))
        {
            echo "The file ". basename($HTTP_POST_FILES['upload1']['name'])." has been sucessfully uploaded";
        }
        else
        {
            echo "There was an error with your upload. Please try again.";
        }
    }
    // Upload 2
    if ( $HTTP_POST_FILES['upload2']['error'] == 0 ) 
    {
        $path2 = $uploadDir . basename( $HTTP_POST_FILES['upload2']['name'] );
        if ( move_uploaded_file ( $HTTP_POST_FILES['upload2']['tmp_name'] , $path2 ))
        {
            echo "The file ". basename($HTTP_POST_FILES['upload2']['name'])." has been sucessfully uploaded";
        }
        else
        {
            echo "There was an error with your upload. Please try again.";
        }
    }
    // Upload 3
    if ( $HTTP_POST_FILES['upload3']['error'] == 0 ) 
    {
        $path3 = $uploadDir . basename( $HTTP_POST_FILES['upload3']['name'] );
        if ( move_uploaded_file ( $HTTP_POST_FILES['upload3']['tmp_name'] , $path3 ))
        {
            echo "The file ". basename($HTTP_POST_FILES['upload3']['name'])." has been sucessfully uploaded";
        }
        else
        {
            echo "There was an error with your upload. Please try again.";
        }
    }
}
?>
<html>
    <head>
        <title> .::Upload::. </title>
    </head>
<body style="font-family: Arial; font-size: 10px;">
<form method="post" enctype="multipart/form-data" action="">
    <input type="hidden" name="MAX_FILE_SIZE" value="650000" />
    File location: <input type="file" name="upload1" /><br />
    File location: <input type="file" name="upload2" /><br />
    File location: <input type="file" name="upload3" /><br />
    <input type="submit" value="Upload" />
</form>
</body>
</html>

(If something is wrong, please tell me. I'm learning this language. Thank you)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users