Wireless Download via Browser...

Discussion in 'Application Ideas' started by KrakaJap, May 15, 2008.

  1. KrakaJap

    KrakaJap New Member

    Joined:
    Oct 18, 2007
    Messages:
    33
    Likes Received:
    0
    I'm working on a php script that will allow me (or anyone on the same net) download music straight from my iPod through a web browser. After installing Apache and PHP this seemed like an incredibly easy project; however, I've hit a brick wall when I go to open the iTunes_Control folder... it doesn't matter what permissions I add to that directory, the sub-directories, or the parent directories, I keep getting a permission denied error.

    Here is my code:
    Code:
    <?php
    	function find_files($path, $pattern, $callback) {
    		$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
    		$matches = Array();
    		$entries = Array();
    		$dir = dir($path);
    		while (false !== ($entry = $dir->read())) {
    			$entries[] = $entry;
    		}
    		$dir->close();
    		foreach ($entries as $entry) {
    			$fullname = $path . $entry;
    			if ($entry != '.' && $entry != '..' && is_dir($fullname)) {
    				find_files($fullname, $pattern, $callback);
    			} else if (is_file($fullname) && preg_match($pattern, $entry)) {
    				call_user_func($callback, $fullname);
    			}
    		}
    	}
    
    	function my_handler($filename) {
    		$id = filesize($filename) - 128;
    		$fp = fopen($filename, "r");
    		fseek($fp, $id);
    		$tag = fread($fp, 3);
    		if ($tag == "TAG") {
    			$title = rtrim(fread($fp, 30));
    			$artist = rtrim(fread($fp, 30));
    			fclose($fp);
    		}
    		echo "<a href='$filename'>$artist - $title<br />";
    	}
    
    	find_files('/private/var/mobile/Media/iTunes_Control/Music', '/mp3/', 'my_handler');
    ?>
    
    On a normal desktop this works perfectly... so I'm going to assume this either as something to do with permissions, virtual directories, or limitations of the PHP version for the iPod (touch).

    The errors I receive in Safari are:
    Any ideas?
  2. optimo

    optimo New Member

    Joined:
    Sep 28, 2007
    Messages:
    535
    Likes Received:
    17
    permissions for sure, I don't have a fix

    you're reinventing the wheel tho, there are apache/lighttpd/php programs that do this already
    phpPod, iSpit, an of the apps that use apache should be broadcasting an http server that you can acceess through the LAN
  3. Ruisu

    Ruisu New Member

    Joined:
    Dec 25, 2007
    Messages:
    65
    Likes Received:
    1
    Would a syslink between the file/directory work??
    Or would you be able to make the PHP script copy the file to the webserver directory and use it?
    I'm not too sure if any of these will work as I hardly know a thing about PHP but I thought I'd give some ideas.
  4. KrakaJap

    KrakaJap New Member

    Joined:
    Oct 18, 2007
    Messages:
    33
    Likes Received:
    0
    not sure about syslink. and copying wouldn't be a great idea considering the small partition.

    optimo: which app does exactly what I'm wanting though? I haven't run into any yet... at least none that only provide me a simple list. I've heard of ones that to all files or all media though. I'm not reinventing the wheel... I'm customizing it to my specific needs.

    Please Register or Log in to view images

    How else are people supposed to learn if they don't try it themselves? I personally think it's much better to know how to write something than to download pre-built apps that simply work. But of course this depends entirely on whether or not you are an end-user or a contributer I suppose. Either way I enjoy it.

    Please Register or Log in to view images

  5. optimo

    optimo New Member

    Joined:
    Sep 28, 2007
    Messages:
    535
    Likes Received:
    17
    yeea you could write your own, its good learning process
    but php filebrowsers is done-to-death, whether there is a new permissions issue with 1.1.4 or not.

    there are several little-known projects and snippets already working(as of 1.1.2). try looking for some information on these forums in the apache or lighttpd threads.

    iSpit, I used to have on 1.1.2, it was just a simple web-index like you see on some websites where it just lists the files and you can go through the folders. You could try to install it. It doesnt use Apache so it's lightweight

    http://www.robota.nl/products/iPhone iSpit.html (look at screenshot to see what I mean) simple

    anyway,the idea is you are probably in the wrong section if you are looking for development help. try the Mods>Applications section, because this 'idea' has already been tackled.

    good luck

    PS: the reason your changing the permissions does not work because apache is runing as 'mobile', may need to run it as 'root'. again, this has probably been covered in the appropriate subforum
  6. KrakaJap

    KrakaJap New Member

    Joined:
    Oct 18, 2007
    Messages:
    33
    Likes Received:
    0
    Will iSpit convert the cryptic naming convention of MP3s on the iPod by reading the ID3 tags? This is basically all I need. That's why I chose to go the "custom" route... I work in an office where (as with almost any office environment) email forwards and music sharing are rampant.

    Please Register or Log in to view images

    Since I don't keep anything like this on my desktop (free of clutter), I thought a simple script to allow easy sharing directly from my iPod to their browsers would be perfect. Thanks for your advice on running Apache as root though... I'll definitely try searching for this. Unless of course you have any ideas on how to accomplish this... the iPod's subsystem doesn't seem to have "sudo" unless I'm missing an addon.
  7. optimo

    optimo New Member

    Joined:
    Sep 28, 2007
    Messages:
    535
    Likes Received:
    17
    ok, I missed that part about reading the tags

    iSpit doesnt do this

    as far as `sudo`, I believe you can find it Cydia package manager. I got no clue about permissions, but I guarantee if you can read through some of the apache topics (the big ones) you will find some good info....because it's probably a problem for most
  8. KrakaJap

    KrakaJap New Member

    Joined:
    Oct 18, 2007
    Messages:
    33
    Likes Received:
    0
    That script I pasted in my first post does this by ID3 tag. All of my music have full ID3 tags and album art... about 70% of them have lyrics.

    Please Register or Log in to view images

    That script works fine... just not on the iPod haha

    From what I've been finding, it looks like I have to parse those directories a different way because of symlink and because Apache is run as web.

Share This Page