-2

Edit: For all those who are downvoting, this isn't the same question asked many times before. I'm NOT A PHP developer. I want to retrieve all the images names from a folder on my FTP server. I googled and found this script:

<?php
foreach (new DirectoryIterator(__DIR__) as $file) {
 if ($file->isFile()) {
 print $file->getFilename() . "\n";
 }
}
?>

Since I'm not a PHP dev, I can't understand even a word of it.

What I Want: Modify PHP script so that it returns an array containing file names and want some android code which accepts the array.

Thank You!

asked Jun 30, 2017 at 8:08
3
  • 1
    what you want is that you need to start reading and learning things. Simple steps: 1) Go to php.net and start find the functions that do what you need to do 2) Export data to json 3) Make an Http Call from Android with (Retrofit, Apache Http, okHttp, HttpurlConnection whatever suits you best) Commented Jun 30, 2017 at 8:14
  • Just fo this small task, I don't want to learn a whole new langauge. Commented Jun 30, 2017 at 8:25
  • 2
    You don't need to learn a whole new langauge. Commented Jun 30, 2017 at 9:21

1 Answer 1

3

I don't know who wrote that method, but PHP already has a built in method to return the contents of a directory http://php.net/manual/en/function.scandir.php

If you only want to include files and not folders with scandir, this answer will help Include JUST files in scandir array?

This answer goes over decoding json with java Decoding JSON String in Java

answered Jun 30, 2017 at 8:09
Sign up to request clarification or add additional context in comments.

7 Comments

I know how to parse JSON by JSON object name, array name but how to decode? Some links please? It would be easy I think
Java. Plus, I read your one line code for json_encode using scandir function. But I want files only and not directories.
I have updated my answer with the details you need. You can easily find this using the search on the site
Everything fine. How to decode '[".","..","0.txt","1.txt","2.txt"]'?
Ok, I have generated the JSON properly now. Before I was doing a bit wrong
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.