What does this error mean? Image Upload

Hi,

I am trying to upload images and am getting this error:

Warning: move_uploaded_file(http://www.freemanholland.com/..../footer.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in /home/migfreem/…/model/db/Product.class.php on line 42

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phppwDDVo’ to ‘http://www.freemanholland.com/.../productimages/footer.jpg’ in /home/…/…/…/public_html/cow/application/model/db/Product.class.php on line 42

This is my code:


    public function uploadImages(){

        $root = "".__SITE_PATH."productimages/";
        
        for($i=1; $i<5; $i++):
            if($_FILES['pic'.$i]['name'] != ''):
                $target_path = $root . basename( $_FILES['pic'.$i]['name']);
                if(move_uploaded_file($_FILES['pic'.$i]['tmp_name'], $target_path)) {
                    echo "The file ".  basename( $_FILES['pic'.$i]['name'])." has been uploaded to ".$root;
                    Thumbnail::createthumb($_FILES['pic'.$i]['name'],$root."tn_".$_FILES['pic'.$i]['name'],81,99);
                    Thumbnail::createthumb($_FILES['pic'.$i]['name'],$root."small_".$_FILES['pic'.$i]['name'],323,390);
                    Thumbnail::createthumb($_FILES['pic'.$i]['name'],$root."category_".$_FILES['pic'.$i]['name'],153,186);
                } else{
                    die("There was an error uploading the file, please try again!");
                }
            endif;
        endfor;
   
    }

Any ideas what the problem is?

Thanks

This is wrong. There shouldn’t be protocol name or hostname, just a path on the filesystem.

Depending on where your public_html is on the harddrive it will be something like:


upload_path = /var/www/vhosts/ABC/public_html/productimages/

Thanks! You guys are legends! :lol:

I changed my code to this:


    public function uploadImages(){

        $root = $_SERVER['DOCUMENT_ROOT']. "/ABC/public_html/productimages/";

        ...//rest of code   
    }

Thanks loads!

Well basically i tried doing this, in my functions.php file, i added this:


define('__UPLOAD_PATH', $paths['site_path']['upload_path']);

And then in my class i did this:


    public function uploadImages(){

        $root = __UPLOAD_PATH;
        
 ......//rest of code
    }

And in my paths.ini.php i set upload_path:


upload_path = http://www.freemanholland.com/ABC/public_html/productimages/

But i get the same error, how am i trying to move a URL i don’t understand :injured:

Off Topic:

Anthony: Touche again :wink:

You’re trying to move the file to a URL rather than a filesystem path. Ie your $target_path is [i]http://www.freemanholland.com/.../productimages/footer.jpg[/i] but should be something like /var/www/vhosts/freemanholland/productimages/footer.jpg depending on where your images are to be stored.

You’re trying to move to a URL, foo’. :stuck_out_tongue:

Change http://www.freemanholland.com/.../productimages/footer.jpg to a local path, you probably don’t want to be using __SITE_PATH.