I would like to try to upload multiple images to a folder on my 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.
In my 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. 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
$files[$index]["tmp_name"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.