本文整理汇总了PHP中Ftp::mkdir方法的典型用法代码示例。如果您正苦于以下问题:PHP Ftp::mkdir方法的具体用法?PHP Ftp::mkdir怎么用?PHP Ftp::mkdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ftp
的用法示例。
在下文中一共展示了Ftp::mkdir方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
if (!$this->input['video_id']) {
$this->errorOutput(NOID);
}
$sql = " SELECT video_base_path,video_path,video_filename,id FROM " . DB_PREFIX . "vodinfo WHERE id IN (" . $this->input['video_id'] . ")";
$q = $this->db->query($sql);
$video = array();
while ($r = $this->db->fetch_array($q)) {
$video[] = $r;
}
//实例化ftp,并连接
$ftp_config = array('hostname' => $this->input['hostname'], 'username' => $this->input['username'], 'password' => $this->input['password']);
$ftp = new Ftp();
if (!$ftp->connect($ftp_config)) {
$this->errorOutput('CAN NOT CONNECT FTP SERVER');
}
foreach ($video as $k => $v) {
$target_dir = date('Y', TIMENOW) . '/' . date('m', TIMENOW) . '/' . TIMENOW . hg_rand_num(6) . '/';
$target_path = $target_dir . $v['video_filename'];
$video_filepath = $v['video_base_path'] . $v['video_path'] . $v['video_filename'];
if (!$ftp->mkdir($target_dir)) {
$this->errorOutput('CAN NOT MAKE DIR');
}
if (!$ftp->upload($video_filepath, $target_path)) {
$this->errorOutput('CAN NOT UPLOAD FILE');
}
$pathinfo = pathinfo($target_path);
$filename = basename($pathinfo['basename'], '.' . $pathinfo['extension']);
$this->addItem(array('path' => $target_path, 'id' => $v['id'], 'dir' => $pathinfo['dirname'], 'filename' => $filename));
}
$this->output();
}
示例2: ftpUpload
/**
* 通过FTP上传图片
* FTP上传不检查文件是否已存在(存在会返回FALSE)
* @param string $uploadformname 需要上传的表单名,$_FILES中
* @return boolean
*/
public function ftpUpload($uploadformname)
{
if (empty($this->_ftpconf)) {
self::$message = '未设置FTP登录信息';
return false;
}
//文件检查
if (!$this->check($uploadformname)) {
return false;
}
//要上传的图片缓存信息
$upfile = $_FILES[$uploadformname];
//图像类型
$imgtype = exif_imagetype($upfile['tmp_name']);
//图片尺寸信息
$size = getimagesize($upfile['tmp_name']);
$ftp = new Ftp();
$constatus = $ftp->connect($this->_ftpconf);
if (!$constatus) {
self::$message = '上传服务器连接失败';
return false;
}
//尝试创建目录,不返回状态,有可能目录已存在
$ftp->mkdir($this->_dir);
$upsatus = $ftp->upload($upfile['tmp_name'], $this->_dir . $this->_savename, '');
if (!$upsatus) {
self::$message = '上传失败,服务器繁忙';
return false;
}
//返回图片属性
self::$picinfo = pathinfo($this->_dir . $this->_savename);
self::$picinfo['width'] = $size[0];
self::$picinfo['height'] = $size[1];
self::$picinfo['size'] = $upfile['size'];
self::$message = '成功';
return true;
}
示例3: ftp_upload
/**
* ftp上传
* @param $file_path:本地文件的路径
* @param $savename:文件名
* @return 1;上传成功<br>
* 0;上传失败
*/
private function ftp_upload($ftp_file_path, $local_file_path, $savename, $type)
{
import("@.ORG.Ftp");
$ftp = new Ftp();
$conn = $ftp->connect('w1.weimg.cn', 'images', 'images580230', $port = '21', $pasv = false, $ssl = false, $timeout = 30);
$ftp->mkdir($ftp_file_path);
$res = $ftp->put($ftp_file_path . $savename, $local_file_path . $savename);
if ($type == 4) {
$ftp->put($ftp_file_path . 's_' . $savename, $local_file_path . 's_' . $savename);
unlink('./Public/upload/s_' . $savename);
}
$ftp->close();
unlink('./Public/upload/' . $savename);
if (!$res) {
return 0;
} else {
return 1;
}
}
示例4: forward_suobei
public function forward_suobei($id)
{
//获取视频id
$sql = 'SELECT content_id,vodid FROM ' . DB_PREFIX . 'materials WHERE content_id IN (' . $id . ') AND vodid !=""';
$query = $this->db->query($sql);
$k = array();
while ($row = $this->db->fetch_array($query)) {
$k[$row['content_id']] = $row['vodid'];
}
$ids = '';
$ret = array();
if (!empty($k)) {
//获取视频信息
$ids = implode(',', $k);
$keys = array_keys($k);
$vodpath = array();
//获取报料标题
$sql = 'SELECT id,title FROM ' . DB_PREFIX . 'content WHERE id IN (' . implode(',', $keys) . ')';
$query = $this->db->query($sql);
$title = array();
while ($row = $this->db->fetch_array($query)) {
$title[$row['id']] = $row['title'];
}
$title = array_combine($k, $title);
$ftp = $this->settings['App_suobei']['ftp'];
$ids = implode(',', $k);
$ret = $this->get_vodinfo($ids, $ftp['host'], $ftp['username'], $ftp['password']);
$vodpath = array();
if (!empty($ret) && is_array($ret)) {
foreach ($ret as $key => $val) {
$vodpath[$val['id']] = $ret[$key];
}
} else {
$this->errorOutput('ftp上传失败');
}
}
if (!empty($vodpath) && !empty($title)) {
//获取报料标题
//写xml文件
$this->vod_xml($vodpath, $title);
//ftp上传
//实例化ftp,并连接
$ftp_config = array('hostname' => $ftp['host'], 'username' => $ftp['username'], 'password' => $ftp['password']);
$ftp_up = new Ftp();
if (!$ftp_up->connect($ftp_config)) {
$this->errorOutput('CAN NOT CONNECT FTP SERVER');
}
foreach ($vodpath as $k => $v) {
$target_dir = $v['dir'] . '/';
$target_path = $target_dir . $v['filename'] . '.xml';
$xml_filepath = $this->settings['App_suobei']['xmldir'] . $v['filename'] . '.xml';
if (!file_exists($xml_filepath)) {
$this->errorOutput('CAN NOT FIND XML');
}
if (!$ftp_up->mkdir($target_dir)) {
$this->errorOutput('CAN NOT MAKE DIR');
}
if (!$ftp_up->upload($xml_filepath, $target_path)) {
$this->errorOutput('CAN NOT UPLOAD FILE');
}
}
$ftp_up->close();
//更新状态位
$sql = 'UPDATE ' . DB_PREFIX . 'content SET suobei=1 WHERE id IN (' . implode(',', $keys) . ')';
$this->db->query($sql);
}
return $id;
}
示例5: upload2ftp
public function upload2ftp()
{
$config = json_decode($this->input['config'], 1);
$files = json_decode($this->input['files'], 1);
include_once ROOT_PATH . 'lib/class/ftp.class.php';
$ftp = new Ftp();
$server_dir = trim($config['server_dir'], '/');
$app_dir = $config['app_dir'];
$message = array('error' => 0);
if (!$ftp->connect($config)) {
$message['error'] = 1;
$message['message'] = '连接服务器失败[' . $config['hostname'] . ']';
}
if ($server_dir && !$message['error']) {
if (!$ftp->mkdir($server_dir)) {
$message['error'] = 2;
$message['message'] = '目标目录不存在且创建失败[' . $server_dir . ']';
}
}
if (!$files && !$message['error']) {
$message['error'] = 3;
$message['message'] = '文件列表不存在[' . $files . ']';
}
if (!$message['error']) {
foreach ($files as $file) {
if (!file_exists($file)) {
//continue;
}
//返回上传错误的文件
$dfile = str_replace($app_dir, '', $file);
//如果设定了ftp目标目录
$dfile = $server_dir ? $server_dir . $dfile : $dfile;
$upload_dir = trim(str_replace('/' . basename($file), '', $dfile), '/');
if ($upload_dir) {
$ftp->mkdir($upload_dir);
}
if (!$ftp->upload($file, $dfile)) {
$message['error'] = 4;
$message['message'][$file] = $dfile;
}
}
}
//file_put_contents(CACHE_DIR . 'debug.txt', var_export($config,1));
$ftp->close();
$this->addItem($message);
$this->output();
}
示例6: upload
/**
* Uploads a file or directory to an FTP connection.
*
* @param \Ftp $ftp An active FTP connection.
* @param \SplFileInfo $file A local file to upload.
*/
protected function upload(\Ftp $ftp, \SplFileInfo $file)
{
// enter into passive mode
$ftp->pasv(true);
// move to the file's parent directory
$ftp->chdir($this->targetDirectory . '/' . $file->getRelativePath());
// check if the file exists
$fileExists = in_array($file->getBasename(), $ftp->nlist('.'));
// check if the file is a directory
if ($file->isDir()) {
// create the directory if it does not exist
if (!$fileExists) {
$this->printTaskInfo('Creating directory: ' . $file->getRelativePathname());
// create directory
$ftp->mkdir($file->getBasename());
}
} else {
// if the file already exists, check our skip options
if ($fileExists) {
// skip the file if the file sizes are equal
if ($this->skipSizeEqual && $ftp->size($file->getBasename()) === $file->getSize()) {
return;
}
// skip the file if modified time is same or newer than source
if ($this->skipUnmodified && $ftp->mdtm($file->getBasename()) >= $file->getMTime()) {
return;
}
}
// try to upload the file
$this->printTaskInfo('Uploading: ' . $file->getRelativePathname());
if (!$ftp->put($file->getBasename(), $file->getRealpath(), FTP_BINARY)) {
// something went wrong
return Result::error($this, 'Failed while uploading file ' . $file->getRelativePathname());
}
}
}
示例7: die
http_response_code(400);
die($error);
}
}
$zipRoot = $zip->getNameIndex(0);
for ($i = 1; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$sourceFile = "zip://{$tmpName}#{$filename}";
$targetFile = str_replace($zipRoot, $target, $filename);
if (is_dir($targetFile)) {
++$dirCount;
continue;
}
$lastChar = substr($sourceFile, -1);
if ($lastChar == $ds || $lastChar == '/') {
if (!$ftp->mkdir($targetFile)) {
$error = "Error creating the directory {$targetFile}";
http_response_code(400);
die($error);
}
continue;
}
$targetDir = dirname($targetFile);
if (!is_dir($targetDir) && !@$ftp->mkdir($targetDir)) {
$error = "Error creating the new folder {$targetDir}";
http_response_code(400);
die($error);
}
if (!$ftp->copy($sourceFile, $targetFile)) {
$error = "Error copying {$filename} to {$targetFile}";
http_response_code(400);
示例8: file_remote_upload
function file_remote_upload($filename)
{
global $_W;
if (empty($_W['setting']['remote']['type'])) {
return false;
}
if ($_W['setting']['remote']['type'] == '1') {
require IA_ROOT . '/framework/library/ftp/ftp.php';
$remoteConfig = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout']);
$ftp = new Ftp($remoteConfig);
if (true === $ftp->connect()) {
$pathinfo = pathinfo($filename);
$dirs = explode('/', $_W['setting']['remote']['ftp']['dir'] . '/' . $pathinfo['dirname']);
$dir = '';
foreach ($dirs as $row) {
if (!empty($row)) {
$dir .= '/' . $row;
$ftp->mkdir($dir);
}
}
$desfile = $_W['setting']['remote']['ftp']['dir'] . '/' . $filename;
if ($ftp->upload(ATTACHMENT_ROOT . '/' . $filename, $desfile)) {
return true;
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
} elseif ($_W['setting']['remote']['type'] == '2') {
require IA_ROOT . '/framework/library/alioss/sdk.class.php';
$oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['url'] . '.aliyuncs.com');
$options = array(ALIOSS::OSS_FILE_UPLOAD => ATTACHMENT_ROOT . '/' . $filename, ALIOSS::OSS_PART_SIZE => 5242880);
$response = $oss->create_mpu_object($_W['setting']['remote']['alioss']['bucket'], $filename, $options);
if ($response->status == 200) {
return true;
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
}
}