Jump to content

Problem with Uploading


jvo

Recommended Posts

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.

[code]
<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>
[/code]

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

Try it.. =)

D.Soul

[code]<?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>[/code]
Link to comment
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.