“图片”文件夹中有1.jpg,2.jpg,3.jpg......;
我现在要用PHP程序指向这个文件夹后点击按钮,直接把“图片”文件夹中的图片上传到upload这个文件夹中,
实现批处理功能
怎么实现这样的功能啊?请提供参考代码!在线等候!

解决方案 »

  1.   

    不明白你的意思
    是把图片文件夹的图片复制到upload文件夹中吗?
      

  2.   

    我是想在本地的文件夹内的所有图片,通过点击一次按钮直接上传到服务器上面的upload文件中
      

  3.   

    服务器上的php不能遍历你客户端的的文件夹, 你可以用js+alex实现, 
      

  4.   

    用foreach循环,读入到一个数组中,然后上传到服务器uplod目录下,你试试
      

  5.   

    $from = './from';
    $to = './to';
    if(!dir($to))mkdir($to, 0777, true);
    $tarr = array('jpg', 'jpg', 'gif', 'png', 'bmp');
    if ($handle = opendir($from)) {
        while (($file = readdir($handle)) !==  false) {
    $arr = explode('.', $file);
    if(count(array_intersect($arr, $tarr))){
    copy($file, $to.'/'.$file);
    }
        }
        closedir($handle);
    }
    echo 'OK';
      

  6.   

    $from = './from';//原图片文件夹
    $to = './to';//复制到的文件夹
    if(!dir($to))mkdir($to, 0777, true);//判断复制到的文件夹是否存在,不存在则创建(权限这里开的是最大,楼主可以自定义,true代表递归穿件文件夹---适合创建多层目录)
    $tarr = array('jpg', 'jpg', 'gif', 'png', 'bmp');//所有的图片类型,当然了这里面这是给出了一部分,如需更多楼主请自行添加
    if ($handle = opendir($from)) {//打开原图片文件夹,返回资源给$handle
        while (($file = readdir($handle)) !==  false) {//循环读取文件夹中读到的资源
    $arr = explode('.', $file);//以 "." 来分割文件名(为后面判断是否是图片最准备)
    if(count(array_intersect($arr, $tarr))){//看上面分割出来的数组中是否存在着数组$tarr(图片类型)中的值(也就是看是否是图片)
    copy($file, $to.'/'.$file);//进行复制
    }
        }
        closedir($handle);//关闭资源
    }
    echo 'OK';
      

  7.   

    用php加FTP吧 这个应该可以实现你大量图片上传到服务器/**
     * Read and upload a folder to ftp server 
     * Copyright (c) 2009, Xu Yulei
     * @author Xu Yulei
     * @license free
     */class FtpUpload{
        /**
         * General function 
         * upload whole folder $aFolder 
         * from $resourcePath to $destinationPath
         * @return 
         * @param $aFolder array folder structure get from readFolder() function
         * @param $destinationPath string
         * @param $resourcePath string
         * @param $ftpStream Object
         */
        public function uploadFolder($aFolder,$destinationPath,$resourcePath,$ftpStream){
            foreach($aFolder as $key=>$value){
                if(is_array ($value)){
                    // create folder $key
                    ftp_mkdir($ftpStream, $destinationPath.'/'.$key);
                    $this->uploadFolder($value,$destinationPath.'/'.$key,$resourcePath.'/'.$key,$ftpStream);
                }
                else{
                    // upload file
                    ftp_put($ftpStream , $destinationPath.'/'.$value,$resourcePath.'/'.$value,FTP_ASCII);
                }
            }        
        }
        
        /**
         * Get folder structure 
         * @return array $aFolder
         * foreach $structure as $key => $value 
         * if key is a number $value = file name
         * if key is a string $value = array repreasent a folder, $key = folder name 
         * @param $path string
         */
        public function readFolder($path){
            $dh = opendir($path);
            $aFolder = array();
            while (($file = readdir($dh)) !== false) {
                if(!(preg_match('/^\.{1,2}$/',$file)||preg_match('/^\.svn[a-z,0-9]*$/',$file))){
                    if(is_dir($path.'/'.$file)){
                        $aFolder[$file] = $this->readFolder($path.'/'.$file);
                    }
                    else{
                        $aFolder[] = $file; 
                    }
                }
            }
            return $aFolder;
        }    
    }
    ?&gt;<?php
    // TEST set
    $ftpStream = ftp_connect('192.168.0.115',21);
    ftp_login($ftpStream,'docseo','comberry');//echo ftp_pwd($ftpStream).'&lt;br/>'; $resourcePath = $_SERVER['DOCUMENT_ROOT']."docseo/docseo_websiteManager/gen/websites/105";
    $destinationPath = 'html/rick';ftp_mkdir($ftpStream, $destinationPath);$oUploader = new FolderUploader();
    $aFolder = $oUploader-&gt;readFolder($resourcePath);
    $oUploader-&gt;uploadFolder($aFolder,$destinationPath,$resourcePath,$ftpStream);
    ftp_close($ftpStream);