PHP Dropbox/Other Cloud Services

From: ANT_THOMAS17 Jul 2012 14:43
To: Peter (BOUGHTONP) 10 of 55

I'll look into those.

 

I have now sorted the problem with a text file but a better solution would be nice.

From: Peter (BOUGHTONP)17 Jul 2012 15:11
To: ANT_THOMAS 11 of 55
The latter is just a PHP wrapper around the former, though it wasn't clear if it implements all the functionality yet, and doing REST with PHP probably isn't hard and might even be a useful skill to have, so I probably wouldn't bother with the wrapper version.
From: ANT_THOMAS17 Jul 2012 17:16
To: ALL12 of 55
Why does this output the HTML over three lines? Or maybe it's not splitting it at all?

PHP code:
echo '<a href="'.$drop.$data.'" class="fancybox"><img src="'.$drop.$data.'" width="190px" /></a>';


I want this....

HTML code:
<a href="http://dl.dropbox.com/u/blah/photo1.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo1.JPG" width="190px" /></a>
<a href="http://dl.dropbox.com/u/blah/photo2.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo2.JPG" width="190px" /></a>
<a href="http://dl.dropbox.com/u/blah/photo3.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo3.JPG" width="190px" /></a>
<a href="http://dl.dropbox.com/u/blah/photo4.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo4.JPG" width="190px" /></a>
<a href="http://dl.dropbox.com/u/blah/photo5.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo5.JPG" width="190px" /></a>


But get this....

HTML code:
<a href="http://dl.dropbox.com/u/blah/photo1.JPG
" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo1.JPG
" width="190px" /></a><a href="http://dl.dropbox.com/u/blah/photo2.JPG
" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo2.JPG
" width="190px" /></a><a href="http://dl.dropbox.com/u/blah/photo3.JPG
" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo3.JPG
" width="190px" /></a><a href="http://dl.dropbox.com/u/blah/photo4.JPG
" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo4.JPG
" width="190px" /></a><a href="http://dl.dropbox.com/u/blah/photo5.JPG" class="fancybox"><img src="http://dl.dropbox.com/u/blah/photo5.JPG" width="190px" /></a>
From: Peter (BOUGHTONP)17 Jul 2012 17:22
To: ANT_THOMAS 13 of 55

There's a stray linebreak on the end of each URL, so probably a stupid carriage return (\r), and thus I'd guess you're only splitting on newline (\n).

 

Either include an optional CR in your split (i.e. \r?\n if it's a regex), or better still set your text file (and any editors you have) to only use single-character newlines, so it doesn't even become an issue.

EDITED: 17 Jul 2012 17:24 by BOUGHTONP
From: ANT_THOMAS17 Jul 2012 17:28
To: ALL14 of 55
I'm about to leave work

Here's the full code if it is of interest
PHP code:
<?php
$dropb = 'http://dl.dropbox.com/u/blah/';
$user_file = @fopen("gallery1.txt", "r");
if ($user_file)
{
	while (!feof($user_file)) 
	{
    	$lines[] = fgets($user_file, 4096);
	}
   	fclose($user_file);
   	foreach($lines as $line => $data)
   	{
   	   	echo '<a href="'. $dropb .''. $data .'" class="fancybox"><img src="'. $dropb .''. $data .'" width="190px" /></a>';
   	}
}
?>


I'll look into fixing it when I get home.
From: Ken (SHIELDSIT)17 Jul 2012 17:34
To: ANT_THOMAS 15 of 55
I thought you were making a dropbox like deal using PHP. I was going to tell you how much I look up to you and how you've always been my favorite. But since you're not doing that I can't say those things to you!
From: ANT_THOMAS17 Jul 2012 17:55
To: Ken (SHIELDSIT) 16 of 55
Ha. That's still on Peter's to do list.
From: Peter (BOUGHTONP)17 Jul 2012 17:57
To: ANT_THOMAS 17 of 55
Hmmm, I'm guessing fgets includes the newline with the string, in which case you can either change that single line to this:
PHP code:
$lines[] = trim(fgets($user_file, 4096);)


Or replace the whole while loop with this:
PHP code:
$lines = preg_split( '\r?\n' , trim(fread($user_file , filesize($user_file))) );
EDITED: 17 Jul 2012 17:58 by BOUGHTONP
From: Peter (BOUGHTONP)17 Jul 2012 17:58
To: Ken (SHIELDSIT) 18 of 55
Dan Herman already did that about ten years about. :P
From: Ken (SHIELDSIT)17 Jul 2012 17:59
To: Peter (BOUGHTONP) 19 of 55
Show me!
From: Peter (BOUGHTONP)17 Jul 2012 18:02
To: Ken (SHIELDSIT) 20 of 55
From: Ken (SHIELDSIT)17 Jul 2012 18:03
To: Peter (BOUGHTONP) 21 of 55
It doesn't look very dropbox like to me.
From: ANT_THOMAS17 Jul 2012 18:04
To: Peter (BOUGHTONP) 22 of 55
I'll give that a go. Thanks.
From: Peter (BOUGHTONP)17 Jul 2012 18:04
To: Ken (SHIELDSIT) 23 of 55
Uh, you're looking at SourceForge aren't you? :S
From: Ken (SHIELDSIT)17 Jul 2012 18:06
To: Peter (BOUGHTONP) 24 of 55
yes.
From: Drew (X3N0PH0N)17 Jul 2012 18:41
To: Peter (BOUGHTONP) 25 of 55
Wow, I'd forgotten that :')
From: ANT_THOMAS17 Jul 2012 18:59
To: Peter (BOUGHTONP) 26 of 55
Works a treat. Thanks PB. Don't believe what the others say, you are helpful!
From: Dan (HERMAND)17 Jul 2012 19:03
To: Peter (BOUGHTONP) 27 of 55

Now there's a blast from the past. Someone on here told me it was a pointless endeavour because anyone who wanted to put files on the Internet would have hosting :-(

 

I ought to be rich...

From: ANT_THOMAS17 Jul 2012 19:09
To: Dan (HERMAND) 28 of 55

:(

 

I blame PB.

From: ANT_THOMAS17 Jul 2012 19:10
To: ALL29 of 55
Dropbox is bloody slow, much slower than the free hosting I found.