Jump to content

[SOLVED] doesnt upload


sandbudd

Recommended Posts

This is to put a upload into a folder to be called by the db but the file is not uploading...any suggestions?

 


/* A function for moving file uploads, please make sure the destination directory has directory permissions set (777) */

    function move_upload( $file, $dest, $overwrite = false )
    {
       
        if ($file["error"] == UPLOAD_ERR_OK)
        {
            if(!file_exists( $dest.$file["name"] ) || $overwrite)
            {
                if (move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))
                {
                    $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";
                    $error            = FALSE;
                }
                else
                {
                    $upload_feedback .= "The file " . $file["name"] . " could not be moved";
                    $error            = TRUE;
                }
            }
            else
            {
                $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";
                $error            = TRUE;
            }
        }
        else
        {
            switch ($file["error"])
            {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";
                    $error            = TRUE;
                break;

                case UPLOAD_ERR_PARTIAL:
                    $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";
                    $error            = TRUE;
                break;
            }
        }

        return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status
    }

    /* All of the uploaded images */
      $attachment   = $_FILES["attachment"];


    /* Destination directory */
    $destination = "../upload/";
   
    /* Call the function to move the files */
      move_upload( $attachment, $destination );
      ?>
<?php
mysql_query("INSERT INTO `items` (`attachment`) VALUES('{$attachment["name"]}')")
or die(mysql_error());
?>

]

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

At the top of the file you have posted add a line

 

<?php

error_reporting(E_ALL);

?>

 

This should report all errors to you.

 

Also check the save to path to make sure it's a there and b able to have files written to it.

Link to comment
Share on other sites

I changed to a different server and I get this error...

 

Notice: Undefined index: attachment in /home/anodizi/public_html/image/upload2.php on line 70

 

Notice: Undefined variable: _files in /home/anodizi/public_html/image/upload2.php on line 76

 

Notice: Undefined variable: files_ in /home/anodizi/public_html/image/upload2.php on line 76

 

here is the code:

 


<?php
/* A function for moving file uploads, please make sure the destination directory has directory permissions set (777) */

    function move_upload( $file, $dest, $overwrite = false )
    {
       
        if ($file["error"] == UPLOAD_ERR_OK)
        {
            if(!file_exists( $dest.$file["name"] ) || $overwrite)
            {
                if (move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))
                {
                    $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";
                    $error            = FALSE;
                }
                else
                {
                    $upload_feedback .= "The file " . $file["name"] . " could not be moved";
                    $error            = TRUE;
                }
            }
            else
            {
                $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";
                $error            = TRUE;
            }
        }
        else
        {
            switch ($file["error"])
            {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";
                    $error            = TRUE;
                break;

                case UPLOAD_ERR_PARTIAL:
                    $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";
                    $error            = TRUE;
                break;
            }
        }

        return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status
    }

    /* All of the uploaded images */
      $attachment   = $_FILES["attachment"];


    
   
    /* Call the function to move the files */
     move_uploaded_file($_files['attachment']['tmp_name'],"http://fortwayneanodizing.com/image/upload/".$files_['attachment']['name']) ; 
      ?>
<?php
mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$attachment["name"]}')")
or die(mysql_error());

?>

Link to comment
Share on other sites

Now i'm not able to see line numbers but from what i can ready

 

Notice: Undefined index: attachment in /home/anodizi/public_html/image/upload2.php on line 70

 

I believe this is your line 70? -> $attachment  = $_FILES["attachment"];

 

this would mean that in the $_FILES array there is no attachment item so there was no field w/ the name 'attachment' used or were not posted.

 

and you should change your _files and files_ both to $_FILES I always use the $_FILES array when i work with file uploads.

Link to comment
Share on other sites

that is where it is at..are you talking about in my form..here is the code

 

<form action="upload2.php" method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input name="file1" type="file" />
<input name="file2" type="file" />
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<p> </p>
</form>

Link to comment
Share on other sites

why not just loop thru the $_FILES and just run the upload function on each item... but to do this you should prob remove the hand coded field value. You pass a var to the function anywhay called $file.

 

So maybe something along the lines of

<?php

$dest = 'my/upload/path';

if(isset($_FILES) && !empty($_FILES) && is_array($_FILES))
{
    foreach($_FILES as $file)
    {
        $upload_msg[$file['name']] = move_upload($file, $dest);
    }
}

?>

 

As far as that function goes... not sure but you can try this

 

<?php

    function move_upload( $file, $dest, $overwrite = false )
    {
       
        if ($file["error"] == UPLOAD_ERR_OK)
        {
            if(!file_exists( $dest.$file["name"] ) || $overwrite)
            {
                if(move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))
                {
                    $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";
                    $error            = FALSE;
                }
                else
                {
                    $upload_feedback .= "The file " . $file["name"] . " could not be moved";
                    $error            = TRUE;
                }
            }
            else
            {
                $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";
                $error            = TRUE;
            }
        }
        else
        {
            switch ($file["error"])
            {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";
                    $error            = TRUE;
                break;

                case UPLOAD_ERR_PARTIAL:
                    $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";
                    $error            = TRUE;
                break;
            }
        }

        return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status
    }

    /* All of the uploaded images */
    $attachment   = $file['name'];

    /* Call the function to move the files */
     move_uploaded_file($file['tmp_name'],"http://fortwayneanodizing.com/image/upload/".$file['name']) ; 
      ?>
<?php
mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$attachment}')")
or die(mysql_error());

?>

Link to comment
Share on other sites

getting closer...here is the code

 


<?php

error_reporting(E_ALL);

?>

<?php

$db_host = ''; // don't forget to change 
$db_user = ''; 
$db_pwd = '';

$database = '';
$table = '';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$dest = 'upload/';

if(isset($_FILES) && !empty($_FILES) && is_array($_FILES))
{
    foreach($_FILES as $file)
    {
        $upload_msg[$file['name']] = move_upload($file, $dest);
    }
}


      function move_upload( $file, $dest, $overwrite = false )
    {
       
        if ($file["error"] == UPLOAD_ERR_OK)
        {
            if(!file_exists( $dest.$file["name"] ) || $overwrite)
            {
                if(move_uploaded_file( $file["tmp_name"], $dest.$file["name"] ))
                {
                    $upload_feedback .= "The file " . $file["name"] . " was successfully uploaded";
                    $error            = FALSE;
                }
                else
                {
                    $upload_feedback .= "The file " . $file["name"] . " could not be moved";
                    $error            = TRUE;
                }
            }
            else
            {
                $upload_feedback .= "The file " . $file["name"] . " already exists, please check the overwrite option if you wish to replace it";
                $error            = TRUE;
            }
        }
        else
        {
            switch ($file["error"])
            {
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    $upload_feedback .= "The file " . $file["name"] . " is to large to be uploaded<br />";
                    $error            = TRUE;
                break;

                case UPLOAD_ERR_PARTIAL:
                    $upload_feedback .= "The file" . $file["name"] . " was interrupted while uploading, please try again<br />";
                    $error            = TRUE;
                break;
            }
        }

        return array( "error" => $error, "feedback" => $upload_feedback ); //return message plus error status
    }

    /* All of the uploaded images */
    $attachment   = $file['name'];

    /* Call the function to move the files */
     move_uploaded_file($file['tmp_name'],"http://fortwayneanodizing.com/image/upload/".$file['name']) ; 
      ?>
<?php
mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$attachment}')")
or die(mysql_error());
?>

 

get this error

 

Notice: Undefined variable: upload_feedback in /home/anodizi/public_html/image/upload2.php on line 42

Link to comment
Share on other sites

ok very easy just after your

 

<?php

$table = '';

?>

 

just add a

 

<?php

$upload_feedback = '';

?>

 

Some pointers for running in E_ALL on all the time, it is VERY strict. This is a fine example if you try to use a Var w/o defining what it is or giving it a value, it will error out... you should always use isset or empty or is_array or w/e to verify your data is what you want it to be... but enough about that let me know if that works for you.

 

 

Link to comment
Share on other sites

wow now I get this

 

Notice: Undefined variable: upload_feedback in /home/anodizi/public_html/image/upload2.php on line 58

 

Warning: move_uploaded_file(http://fortwayneanodizing.com/image/upload/gb.gif) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in /home/anodizi/public_html/image/upload2.php on line 87

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpcjIPFN' to 'http://fortwayneanodizing.com/image/upload/gb.gif' in /home/anodizi/public_html/image/upload2.php on line 87

Link to comment
Share on other sites

This is whre you may need to check into your PHP ini settings 1st make sure that file uploads are on... after that I'm not sure... never ran into that problem...

 

Now it also looks like the file may already be there... did you check that?

Link to comment
Share on other sites

this is what I get

 

array(1) { ["attachment"]=>  array(5) { ["name"]=>  string(18) "Hawaii2008 095.jpg" ["type"]=>  string(10) "image/jpeg" ["tmp_name"]=>  string(14) "/tmp/php4ja7PN" ["error"]=>  int(0) ["size"]=>  int(258368) } }

Notice: Undefined variable: upload_feedback in /home/anodizi/public_html/image/upload2.php on line 48

Link to comment
Share on other sites

Sure, sorry about that.  Look at this line:

 

move_uploaded_file($file['tmp_name'],"http://fortwayneanodizing.com/image/upload/".$file['name']);

 

You need to pass it "image/upload/{$file['name']}" instead, so it puts it on the filesystem instead of trying to open the web page.  You need to supply the relative or absolute path.  Understand? :o

Link to comment
Share on other sites

DarkWater I changed it to this

 

 

    /* All of the uploaded images */

    $attachment  = $file['name'];

 

    /* Call the function to move the files */

    move_uploaded_file($file['tmp_name'],"upload/{$file['name']}".$file['name']) ;

      ?>

<?php

mysql_query("INSERT INTO items(attachment) VALUES('$attachment')") ;

 

or die(mysql_error());

?>

 

and get this error with nothing uploading?

 

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/anodizi/public_html/image/upload2.php on line 93

 

 

this is line 93

 

or die(mysql_error());

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.