1

I'm developing a website for showcasing few products and I have stored all my images in a public/images/ now I want to take it step by step. So I just want to count the number of images in the folder and display it on the screen like,If the user click on a particular product it should display x number of product available and then it should display all the images,the displaying part is not necessary for now. I just was to count and display in the screen.

I'm using xampp for testing locally and my project is in Laravel 5.0

This is what I have tried so far in ajax

 var dir = 'public/images/homePage/';
    var fileextension = ".jpg";
    $.ajax({
        type: 'GET'
        , url: dir
        , dataType: 'text'
        , success: function (data) {
            console.log('able to access');
        }
        , error: function (req, status, err) {
            console.log("error" + err + status);
        }
    });

I am just getting 404 Not Found error,I have no idea about what is wrong.

Rehan
  • 3,813
  • 7
  • 37
  • 58
  • You gotta be kidding right? A duplicate of http://stackoverflow.com/questions/37634049/how-to-print-all-the-txt-files-inside-a-folder-using-java-script ?!?! You need to read a bit more carefully before flagging @guest271314 – Vinay Mar 07 '17 at 03:05
  • @Novice How so? Does third approach at http://stackoverflow.com/a/37634328/ not resolve present Question? – guest271314 Mar 07 '17 at 03:11
  • Sorry if I am mistaken but it looks like OP wants to calculate files present **on the server** and not on his local machine .Although his client and server are on same machine for now but that is irrelevant.`I'm developing a website for showcasing few products and I have stored all my images in a public/images/` – Vinay Mar 07 '17 at 03:38
  • @Novice Yes, either count successful requests client side or have server respond once with count of files. OP does not attempt to create server response at code at Question, rather uses `$.ajax()` to? Solution is either OP provides greater detail as to expected file names, or compose a server side response, after server counts specific files in directory having specific `MIME` type. Do you suggest Question be re-opened? If yes, can you provide clarity as to what is expected solution given current text of Question? You can vote for Question to be re-opened. – guest271314 Mar 07 '17 at 03:40
  • `$.ajax()` wud sent a path present *on the server* which server would read and find the no. of files in present in that path , which would then sent back to client to display onto the screen much like a remote file browser – Vinay Mar 07 '17 at 03:45
  • @Novice Yes, where does OP attempt to compose server side code and response? Or, is OP asking for the server side code to be written for them? – guest271314 Mar 07 '17 at 03:46
  • @guest271314 Yea he doesn't but he must be doing it otherwise why he'd use laravel? – Vinay Mar 07 '17 at 03:48
  • @Novice _"Yea he doesn't but he must be doing it otherwise why he'd use laravel?"_ Not sure. No description of attempts to solve Question server side appear at actual Question. "he must be doing it" cannot be substantiated by text of Question. See http://stackoverflow.com/help/mcve, http://stackoverflow.com/help/how-to-ask. OP should be aware of the file names at local server. Create an array of file names and use `HEAD` or `GET` request, if successful, increment a count variable, as demonstrated at linked Question. OP cannot expect viewers to both guess file names and or write server code. – guest271314 Mar 07 '17 at 03:49
  • @Novice For obvious reasons, `$.ajax()` alone, without file names or server expecting request, will not return expected results. Are you suggesting Question be re-opened so that you can post a modified `$.ajax()` request and `php` solution to the Question? – guest271314 Mar 07 '17 at 04:00
  • No, actually It looked to me as a similar problem which I solved recently in a remote file explorer which wud show files just like in your local explorer in that browser requests '/' and gets lists of files.In subsequent requests browser wud send paths to server and gets files and folders shown.But you're right I asumed server is there in OP's scenario which he didn't suggest – Vinay Mar 07 '17 at 11:21
  • woah that was pretty intense discussion. I was doing it wrongly as I didn't write any routes to that particular `link`,I browsed through the internet and found out that it was the routing issue. Anyway thanks folks :) – Rehan Mar 07 '17 at 16:45

0 Answers0