“图片”文件夹中有1.jpg,2.jpg,3.jpg......;
我现在要用PHP程序指向这个文件夹后点击按钮,直接把“图片”文件夹中的图片上传到upload这个文件夹中,
实现批处理功能
怎么实现这样的功能啊?请提供参考代码!在线等候!
我现在要用PHP程序指向这个文件夹后点击按钮,直接把“图片”文件夹中的图片上传到upload这个文件夹中,
实现批处理功能
怎么实现这样的功能啊?请提供参考代码!在线等候!
解决方案 »
- 服务器禁用了exec,system,passthru,popen,pclose,shell_exec,proc_open,curl_exec,multi_exe
- json 字符串 转换成php数组
- 遇到一个问题,请问这个正则表达式是什么意思?
- 送分啦,好简单的PHP函数问题,不拿白不拿了~~~
- 如何关闭窗口
- 在线急等,关于怎么保存网页的数据到数据库里呀
- 各位:重分请教小问题!关于phpmyadmin的安装!!!! 谢谢大家!小弟在线等待!!小弟在线等待!!小弟在线等待!!
- 怎么搞定这个SESSION的警告问题?
- 字符替换的问题(急)
- 在注册页,当提交后为什么会出现源码呢?
- 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);