Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Location
    Oakham England
    Posts
    499

    Multi File Upload

    Hey,

    I have the following but get a Warning: Invalid argument supplied for foreach()

    So I have an upload form with multi files such as:

    <input name="img[34]" type="file" id="img[34]" />
    <input name="img[37]" type="file" id="img[37]" />

    Then on submit it send this:
    $up->UploadArt($_FILE['img']);

    To this part of the class:
    PHP Code:
    public function UploadArt($files){
                foreach(
    $files as $lid => $file){
                    
    $allowedExts = array("gif""jpeg""jpg""png");
                    
    $temp explode("."$file["name"]);
                    
    $extension end($temp);
                    if (((
    $file["type"] == "image/gif")
                    || (
    $file["type"] == "image/jpeg")
                    || (
    $file["type"] == "image/jpg")
                    || (
    $file["type"] == "image/pjpeg")
                    || (
    $file["type"] == "image/x-png")
                    || (
    $file["type"] == "image/png"))
                    && (
    $file["size"] < 20000)
                    && 
    in_array($extension$allowedExts)){
                        
                        
    $nfn md5(time()) . "." $extension;
                        
    move_uploaded_file($file["tmp_name"], "../uploads/" $nfn);
                        
                        
    $this->db->query('UPDATE `lines` SET `file` = :file WHERE `id` = :id');
                        
    $this->db->bind(':file',    "uploads/" $nfn);
                        
    $this->db->bind(':id',        $lid);
                        
    $this->db->execute();
                    }
                }
                
                return 
    true;
            } 
    However its not working what am I doing wrong?
    Dan
    Streama - Your WordPress Friend
    http://www.streama.co.uk

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Quote Originally Posted by Danny159 View Post
    $up->UploadArt($_FILE['img']);
    Presumably you wanted the superglobal $_FILES. Even then IDK that $_FILES['img'] will give you the associative array that function is expecting. Use var_dump to check.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Aug 2007
    Location
    Oakham England
    Posts
    499
    Thanks! Helps when you get someone elses eyes on it.

    Dan
    Streama - Your WordPress Friend
    http://www.streama.co.uk

Similar Threads

  1. how to increase the upload file size of mysql upload
    By sc0rpian in forum Web Hosting
    Replies: 8
    Last Post: 10-08-2012, 11:53 AM
  2. Replies: 1
    Last Post: 02-18-2010, 09:43 AM
  3. I was upload file but it can't display and it missing from file manager?
    By rossen in forum Hosting Security and Technology
    Replies: 2
    Last Post: 06-11-2008, 10:50 AM
  4. PhP upload script doesn't upload the file.
    By Nullified in forum Programming Discussion
    Replies: 7
    Last Post: 06-24-2004, 09:46 PM
  5. Upload file using pur ASP and file system object
    By bigmonster51 in forum Programming Discussion
    Replies: 0
    Last Post: 01-22-2004, 09:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •