做个PHP上传批处理上传图片功能,说明如下,高手光顾一下! “图片”文件夹中有1.jpg,2.jpg,3.jpg......;我现在要用PHP程序指向这个文件夹后点击按钮,直接把“图片”文件夹中的图片上传到upload这个文件夹中,实现批处理功能怎么实现这样的功能啊?请提供参考代码!在线等候! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不明白你的意思是把图片文件夹的图片复制到upload文件夹中吗? 我是想在本地的文件夹内的所有图片,通过点击一次按钮直接上传到服务器上面的upload文件中 服务器上的php不能遍历你客户端的的文件夹, 你可以用js+alex实现, 用foreach循环,读入到一个数组中,然后上传到服务器uplod目录下,你试试 $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'; $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'; 用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; } }?><?php// TEST set$ftpStream = ftp_connect('192.168.0.115',21);ftp_login($ftpStream,'docseo','comberry');//echo ftp_pwd($ftpStream).'<br/>'; $resourcePath = $_SERVER['DOCUMENT_ROOT']."docseo/docseo_websiteManager/gen/websites/105";$destinationPath = 'html/rick';ftp_mkdir($ftpStream, $destinationPath);$oUploader = new FolderUploader();$aFolder = $oUploader->readFolder($resourcePath);$oUploader->uploadFolder($aFolder,$destinationPath,$resourcePath,$ftpStream);ftp_close($ftpStream); PHP返回值判断问题 在多维增加一个key,key的值需要取 zend studio 5.5单步调试 php判断提示 谁用过php下面的tidy?有问题请教。[内详] 关于树型菜单和frameset的问题。 linux下php的配置问题(Cannot modify header information... 给300分!) 求教一sql语句,大家帮我看看,谢 紧急求助!!位什么我的php不能解释表单传递过来的变量???载线等待!! 采集网站信息时,对方限制改如何解决才能采集 js改写成jquery 为什么在页面输入如下的private,就提示出错?
是把图片文件夹的图片复制到upload文件夹中吗?
$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';
$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';
* 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;
}
}
?><?php
// TEST set
$ftpStream = ftp_connect('192.168.0.115',21);
ftp_login($ftpStream,'docseo','comberry');//echo ftp_pwd($ftpStream).'<br/>'; $resourcePath = $_SERVER['DOCUMENT_ROOT']."docseo/docseo_websiteManager/gen/websites/105";
$destinationPath = 'html/rick';ftp_mkdir($ftpStream, $destinationPath);$oUploader = new FolderUploader();
$aFolder = $oUploader->readFolder($resourcePath);
$oUploader->uploadFolder($aFolder,$destinationPath,$resourcePath,$ftpStream);
ftp_close($ftpStream);