本文整理汇总了PHP中Ftp::uploadfile方法的典型用法代码示例。如果您正苦于以下问题:PHP Ftp::uploadfile方法的具体用法?PHP Ftp::uploadfile怎么用?PHP Ftp::uploadfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ftp
的用法示例。
在下文中一共展示了Ftp::uploadfile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadIcon
public function uploadIcon($file)
{
$filename = $file->getName();
//获取文件名
$filename = F::random_filename() . '.' . pathinfo($filename, PATHINFO_EXTENSION);
$filesize = $file->getSize();
//获取文件大小
$filetype = $file->getType();
//获取文件类型
$filePath = Yii::app()->params->uploadPath . "tmp/";
if (!file_exists($filePath)) {
mkdir($filePath, 0777);
}
if ($file->saveAs($filePath . $filename, true)) {
$ftpsavepath = 'common/frontmenu/';
$ftp = new Ftp();
$res = $ftp->uploadfile($filePath . $filename, $ftpsavepath . $filename);
$ftp->close();
if ($res['success']) {
@unlink($filePath . $filename);
return $filename;
} else {
var_dump($res);
die;
}
}
}
示例2: actionUploadFile
public function actionUploadFile()
{
$path = $_POST['path'];
if (!empty($_FILES)) {
$oldfileName = $_FILES['Filedata']['name'];
$ext = substr($oldfileName, strrpos($oldfileName, ".") + 1);
$filesize = $_FILES['Filedata']['size'];
//上传文件大小
$fileName = $this->getRandomName($oldfileName);
$tmpFile = $_FILES['Filedata']['tmp_name'];
//缓存文件路径
//$type = $_FILES['Filedata']['type']; //上传文件类型
$tp = array('gif', 'jpg', 'png', 'bmp', 'jpeg', 'doc', 'docx', 'xls', 'xlsx', 'txt');
//检查上传文件是否在允许上传的类型
if (!in_array($ext, $tp)) {
echo json_encode(array('code' => 1, 'msg' => '只能发送图片、文档、表格等文件'));
die;
}
if (in_array($ext, array('gif', 'jpg', 'png', 'bmp', 'jpeg'))) {
$ftype = 1;
} else {
$ftype = 2;
}
//检查文件大小
$max_size = 2 * 1024 * 1024;
//2M
if ($filesize > $max_size) {
echo json_encode(array('code' => 0, 'msg' => '上传文件大小超过限制,不允许超过2M '));
die;
}
//上传文件临时保存路径
$tmpsavepath = Yii::app()->params['uploadPath'] . 'tmp/';
if (!file_exists($tmpsavepath)) {
if (!@mkdir($tmpsavepath, 0777, true)) {
echo json_encode(array('code' => 0, 'msg' => '临时保存目录创建失败 - ' . $tmpsavepath));
die;
} else {
chmod($tmpsavepath, 0777);
}
}
//检查目录写权限
if (@is_writable($tmpsavepath) === false) {
echo json_encode(array('code' => 0, 'msg' => '临时保存目录没有写权限 - ' . $tmpsavepath));
die;
}
$tmpsavefile = $tmpsavepath . basename($tmpFile);
if (@move_uploaded_file($tmpFile, $tmpsavefile) === false) {
echo json_encode(array('code' => 0, 'msg' => '文件保存失败 - ' . $tmpsavefile));
die;
}
$fileurl = $path . $fileName;
// 新文件名
$ftp = new Ftp();
$res = $ftp->uploadfile($tmpsavefile, $fileurl);
$ftp->close();
if ($res['success']) {
@unlink($tmpsavefile);
//删除临时文件
echo json_encode(array('code' => 200, 'ftype' => $ftype, 'fileurl' => $fileurl, 'filename' => $oldfileName, 'msg' => '上传成功!'));
} else {
echo json_encode(array('code' => 0, 'msg' => $res['msg']));
}
} else {
echo json_encode(array('code' => 0, 'msg' => '请选择文件!'));
}
}
示例3: actionEditlogo
public function actionEditlogo()
{
$organID = Yii::app()->user->OrganID;
//organ表单验证
$model = Organ::model()->findByPK($organID);
if ($model->Logo) {
//删除
$ftp = new Ftp();
$res = $ftp->delete_file($model->Logo);
$ftp->close();
}
//获得一个CUploadedFile的实例
$file = CUploadedFile::getInstanceByName('Logo');
$rs = array('code' => 100, 'msg' => '上传失败!' . $ImgName . '已经上传');
$upload = Yii::app()->params['uploadPath'] . 'tmp/logo/' . $organID . '/';
$path = Yii::app()->params['uploadPath'] . 'tmp/';
if (!is_dir($upload)) {
mkdir($upload, 0777, true) or die('创建失败');
chmod($upload, 0777);
}
// 判断实例化是否成功
if (is_object($file) && get_class($file) === 'CUploadedFile') {
$model->Logo = 'logo/' . $organID . '/' . 'file_' . date("YmdHis") . '_' . rand(1000, 9999) . '.' . $file->extensionName;
//定义文件保存的名称
}
/* else{ // 若果失败则应该是什么图片
$model->url = './assets/upfile/noPic.jpg';
} */
if ($model->save()) {
$file->saveAs($path . $model->Logo, true);
$ftp = new Ftp();
$res = $ftp->uploadfile($path . $model->Logo, $model->Logo);
$ftp->close();
@unlink($path . $model->Logo);
}
$this->redirect(array('index'));
}
示例4: actionFtpUpload
public function actionFtpUpload()
{
$path = $_POST['path'];
if (!empty($_FILES)) {
$oldfileName = $_FILES['Filedata']['name'];
$filesize = $_FILES['Filedata']['size'];
$fileName = $this->getRandomName($oldfileName);
$tmpFile = $_FILES['Filedata']['tmp_name'];
//缓存文件路径
//上传文件临时保存路径
$tmpsavepath = Yii::app()->params['uploadPath'] . 'tmp/';
if (!file_exists($tmpsavepath)) {
if (!@mkdir($tmpsavepath, 0777, true)) {
echo json_encode(array('code' => 0, 'msg' => '临时保存目录创建失败 - ' . $tmpsavepath));
die;
} else {
chmod($tmpsavepath, 0777);
}
}
//检查目录写权限
if (@is_writable($tmpsavepath) === false) {
echo json_encode(array('code' => 0, 'msg' => '临时保存目录没有写权限 - ' . $tmpsavepath));
die;
}
//检查文件大小
$max_size = 2 * 1024 * 1024;
//2M
if ($filesize > $max_size) {
echo json_encode(array('code' => 0, 'msg' => '上传文件大小超过限制,不允许超过2M '));
die;
}
$tmpsavefile = $tmpsavepath . basename($tmpFile);
if (@move_uploaded_file($tmpFile, $tmpsavefile) === false) {
echo json_encode(array('code' => 0, 'msg' => '文件保存失败 - ' . $tmpsavefile));
die;
}
$fileurl = $path . $fileName;
// 新文件名
$ftp = new Ftp();
$res = $ftp->uploadfile($tmpsavefile, $fileurl);
$ftp->close();
if ($res['success']) {
@unlink($tmpsavefile);
//删除临时文件
echo json_encode(array('code' => 200, 'fileurl' => $fileurl, 'ftpfileurl' => $res['url'], 'filename' => $oldfileName, 'msg' => '上传成功!'));
} else {
echo json_encode(array('code' => 0, 'msg' => $res['msg']));
}
} else {
echo json_encode(array('code' => 0, 'msg' => '请选择文件!'));
}
}