Jump to content

Need Help reading a directory and inserting contents to mysql


asaschool

Recommended Posts

Hello All,

First off I want to say thank you to whoever reads this, any help is appreciated. OK I have a project where I need to download the contents of a directory into a mysql database, but its a little bit more complex than it sounds (or at least thats what I am finding out with my efforts). The directory is located on an ftp server which requires a username and password. In this directory are 32 zip files that contain photos and data that is in a format where records are separated by " | " and end with a return (example: 107438|RESI|RESI|600|8945000.00|16873|Out of Area|4|5|Attached|3||0|26290.19|8000|P|1990|0.867|Office/Den,Study). There are about 80 columns of data and several hundred rows per zip file. All photos are jpg.

 

I need my script to parse each zip file and put all new data into my database which is searchable. My database is configured in the same order as the information is separated. I was going to set up a cron job to automate the script and refresh the database every-night. I dont need to download the pictures binary data to my database, I just want to move them into a separate folder on my server and record the files location in my database (this is how I am doing it with other applications). Can anyone give me an idea of how to get my script to parse this directory on the ftp and prepare the data for mysql insertion. This is where my problem is. I cannot seem to write a correct script that locates the data. All my efforts are being squashed before I even reach the data. I am very familiar and php and mysql and just need some advise on the best way to go about this.

 

Thanks again for any help!

More...

 

The connection script I am using is very simple, but it still does not connect me. I can connect fine through other process' so I know my login information is correct. I get two results from using this script. if I direct ftp_connect to ftp.ftpserver.com I get a dropped connection error from my browser. If I direct ftp_connect to ftp://ftp.ftpserver.com I get the following errors:

 

Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

 

Warning: ftp_login() expects parameter 1 to be resource, boolean given

 

ftp connection script I am trying to use:

 

<?php

$ftp_server = 'ftp.ftpserver.com';

$ftp_user_name = 'User';

$ftp_user_pass = 'Pass';

 

// set up basic connection

$conn_id = ftp_connect($ftp_server, $ftp_port);

 

// login with username and password

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

 

// check connection

if ((!$conn_id) || (!$login_result)) {

echo "Ftp connection has failed!";

echo "Attempted to connect to $ftp_server for user $ftp_user_name";

die;

} else {

echo "Connected to $ftp_server, for user $ftp_user_name";

}

 

// close the FTP stream

ftp_close($conn_id);

?>

 

Thanks again for any help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.