我需要使用php和ftp上传一些视频和音频文件。我正在使用php内置的ftp函数,但是该ftp_put()函数存在一些问题。在测试代码时,它将继续给我一个与文件名有关的错误。我该如何解决。这是我尝试上传文件时php控制台的输出:Warning: ftp_put(): Filename cannot be empty in /Users/uc/Desktop/c/FtpManager.php on line 37这是$_FILES数组转储: array(5) { ["name"]=> string(8) "em_1.mp4" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(1) ["size"]=> int(0) }我用于脚本原型的代码如下:<?php /* Upload video */ public function uploadVideo(array $inputFile){ if( ftp_chdir( $this->conn, "/cloud.mywebsite.com/" ) ){ $upload = ftp_put( $this->conn, $inputFile['video_file']['name'], $inputFile['video_file']['name'], FTP_BINARY); if( $upload ){ echo 'File uploaded!'; } } }if(isset($_POST['upload_video'])){ echo $ftp->uploadVideo($_FILES['video_file']);}?><form enctype="multipart/form-data" method="POST" action=""> <input type="file" name="video_file" /> <input type="submit" name="upload_video"></form>
2 回答
catspeake
TA贡献1111条经验 获得超0个赞
错误的常见原因是超出了maximum allowed filesize。至少,$_FILES在尝试上传FTP之前,请检查文件条目中的错误
if ($_FILES['video_file']['error'] != UPLOAD_ERR_OK) {
// handle the error instead of uploading e.g. give a message to user
}
- 2 回答
- 0 关注
- 213 浏览
添加回答
举报
0/150
提交
取消