[英]image upload to ftp with arrays php
I would like to try to upload multiple images to a folder on my FTP. 我想尝试将多个图像上传到FTP上的文件夹。 I tried already uploading to my database, and that worked with my code.
我已经尝试将其上传到数据库,并且可以使用我的代码。 It's the first time I'm writing code to upload a file to the FTP.
这是我第一次编写将文件上传到FTP的代码。
In my config.php: 在我的config.php中:
$ftp_server = "**";
$ftp_username = "**";
$ftp_password= "**";
$connect = mysql_connect($ftp_server, $ftp_username, $ftp_password)
or die ("Hey, check your server connection.");
Code to upload file: 上传文件的代码:
include_once '..includes/config.php';
$files = array();
$fdata = $_FILES['image'];
if (is_array($fdata['name'])) {
for($i=0;$i<count($fdata['name']);$i++) {
$files[] = array(
'name' => $fdata['name'][$i],
'tmp_name' => $fdata['tmp_name'][$i]
);
}
} else $files[] = $fdata;
foreach($files as $file) {
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
ftp_put($conn_id, "public_html/img/" . $file['name'],$file['tmp_name']),FTP_BINARY);
print_r($files['tmp_name']);
}
When I try to print my $files['tmp_name']
, I get an blanc page and the file isn't uploaded to my FTP. 当我尝试打印
$files['tmp_name']
,出现空白页面,并且文件未上传到FTP。 Can somebody help me? 有人可以帮我吗?
Thanks. 谢谢。
I think you need to add an index to your files assignation, like this: 我认为您需要为文件分配添加索引,如下所示:
$files[$i] = array(
'name' => $fdata['name'][$i],
'tmp_name' => $fdata['tmp_name'][$i]
);
Then you would get tmp_name of whatever index you want 然后,您将获得所需的任何索引的tmp_name
$files[$index]["tmp_name"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.