Jump to content

[SOLVED] doesnt upload


sandbudd

Recommended Posts

  • Replies 62
  • Created
  • Last Reply

now I get this and one file does upload instead of 2

 

Warning: move_uploaded_file(image/Hawaii2008 017.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/anodizi/public_html/image/upload2.php on line 44

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjQvFPO' to 'image/Hawaii2008 017.jpg' in /home/anodizi/public_html/image/upload2.php on line 44

 

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

 

Warning: move_uploaded_file(image/Hawaii2008 018.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/anodizi/public_html/image/upload2.php on line 44

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpAC1WLq' to 'image/Hawaii2008 018.jpg' in /home/anodizi/public_html/image/upload2.php on line 44

 

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

DarkWater there is an upload directory in the image folder I am not sure how to loop them do I do something like

 


/* All of the uploaded images */ $attachment_1 =
$_FILES["file1"]; $attachment_2 = $_FILES["file2"]; /* Destination
directory */ $destination = "upload/"; /* Call the function to move
the files */ move_upload( $attachment_1, $destination ); move_upload(
$attachment_2, $destination ); ?>
<?php
mysql_query("INSERT INTO items(attachment) VALUES('$attachment_1')") ;
mysql_query("INSERT INTO items(attachment) VALUES('$attachment_2')") ;
or die(mysql_error());

This code uploads both to the upload folder but only one in the db?

 


<?php

error_reporting(E_ALL);

?>

<?php

$db_host = ''; 
$db_user = ''; 
$db_pwd = '';

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


$upload_feedback = '';
var_dump($_FILES);



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'],"image/upload/".$file['name']) ; 
      ?>
<?php
mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$attachment}')")
or die(mysql_error());
?>

I didn't know you had that foreach on top.  That explains a lot.  You need to remove two lines near the bottom...I'll do it.  Here:


<?php

error_reporting(E_ALL);

?>

<?php

$db_host = ''; 
$db_user = ''; 
$db_pwd = '';

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


$upload_feedback = '';
var_dump($_FILES);



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
    }
?>
<?php
foreach ($_FILES as $file) {
mysql_query("INSERT INTO `upload` (`attachment`) VALUES('{$file['name']}')")
or die(mysql_error());
}
?>

this is the array...that is why I asked should I have different fields in the db file1, file2,

 

array(2) { ["file1"]=>  array(5) { ["name"]=>  string(18) "Hawaii2008 021.jpg" ["type"]=>  string(10) "image/jpeg" ["tmp_name"]=>  string(14) "/tmp/phpWo6Qjb" ["error"]=>  int(0) ["size"]=>  int(1312069) } ["file2"]=>  array(5) { ["name"]=>  string(18) "Hawaii2008 023.jpg" ["type"]=>  string(10) "image/jpeg" ["tmp_name"]=>  string(14) "/tmp/phpk7bgva" ["error"]=>  int(0) ["size"]=>  int(1356596) } }

Alright...is it just going to be like a "file upload" thing where you can just see all the files people uploaded?  Ex:

1) John uploads somefile.jpg.

 

2) Joe checks your site, sees somefile.jpg, and wants it, so he downloads it.

 

Am I right?  Then every file should have different IDs.

someone suggested this but I couldnt get it to work....

 

/* All of the uploaded images */ $attachment_1 =

$_FILES["file1"]; $attachment_2 = $_FILES["file2"]; /* Destination

directory */ $destination = "../upload/"; /* Call the function to move

the files */ move_upload( $attachment_1, $destination ); move_upload(

$attachment_2, $destination ); ?>

<?php

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

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

or die(mysql_error());

?>

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.