I'm developing a plugin which getting data as CSV file. Then i should upload the images from an other server to my server using the details of this CSV file. The problem is the coding which is not in my Wordpress file is working. But when i put the same file i to the Wordpress plugin folder, then it create only the csv file, but it doesn't upload the images from the other server to my server. Below is the coding that i use for it.(I gave all the file permission 777).

$handle = fopen('agentListing.csv', 'r');
$row = fgetcsv($handle);
while (($row = fgetcsv($handle)) !== false) 
    print '$row[130]--->'.$row[130].'<br>';
    $dir = substr($row[130], -3); 
    $fileno = $row[130];
    $ftpup = "./photos/";
    $local_file ="./photos/{$fileno}.jpg";
    $server_file = "/mlsmultiphotos/1/{$dir}/{$fileno}.jpg";

    // set up basic connection
$conn_id = ftp_connect('3pv.torontomls.net') or die("Couldn't connect to $ftp_server");

// login with username and password
$login_result = ftp_login($conn_id, 'user@photos', 'Password');
exec('touch {$local_file}');
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";

You've got a path problem. When the plugin executes, any reference to a file is relative to the plugin folder.

Use developer tools (like Firebug) to see the actual request for the jpg file. You'll see that it is trying to find the jpg file in the plugin folder. Adjust the path to the files.

Take a look at the get_template_directory_uri() function to help you get the proper path for your images. See https://developer.wordpress.org/reference/functions/get_template_directory_uri/ .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.