Jump to content

[SOLVED] doesnt upload


sandbudd

Recommended Posts

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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());
?>

Link to comment
Share on other sites

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());
}
?>

Link to comment
Share on other sites

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) } }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());

?>

Link to comment
Share on other sites

Table structure for table `upload`
--

CREATE TABLE IF NOT EXISTS `upload` (
  `id` int(10) NOT NULL auto_increment,
  `attachment` varchar(50) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=59 ;

Link to comment
Share on other sites

Sorry, I took a shower and then the power died for a little bit. O_O 

 

So, now, are you associating the files with a user, a specific album, or do you have SOME way of joining them other than giving the same ID (which is SUPPOSED to be unique)?

Link to comment
Share on other sites

yes it is a request for quote form that someone would fill out and submit along with multiple file attachments that goes to a display results page...that is why I need the images that are uploaded for that person to be together.

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.