123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|570|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> Debugging PHP

Mon, 28 Mar 2011, 01:32
Afr0
I have the following code;



It is supposed to generate an HTML page with links to 3 PDFs on it, but it only generates 2! There are three PDFs in total! What am I doing wrong?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 28 Mar 2011, 01:39
Jayenkai
Not sure why you're doing a += 2.. should be just ++, shouldn't it?!
Maybe I'm reading it wrong!? *shrugs*

You're counting JPGFiles in both loops.

-=-=-
''Load, Next List!''
Mon, 28 Mar 2011, 01:41
Afr0
Yes, I'm assuming that the number of JPGFiles and PDFFiles will be the same. I'm trying to loop across two files at once!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 28 Mar 2011, 01:45
Afr0
When I change the loop to:



It starts pumping out thousands of temp files! *sigh*

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 28 Mar 2011, 07:36
HoboBen
What's the output of:

var_dump(GetDirectoryList("PDFs", "pdf"));
var_dump(GetDirectoryList("PDFs", "jpg"));

?

-=-=-
blog | work | code | more code
Mon, 28 Mar 2011, 09:25
Afr0
I fixed it!
I will post the full code at work tomorrow

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 30 Mar 2011, 03:00
Afr0


I also had to CHMOD the 'tmpsites' directory to allow the PHP script to write to it.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 30 Mar 2011, 03:08
JL235
I don't quite understand what you are building. Why are you writing to all those files? Won't that happen on every page request?
Wed, 30 Mar 2011, 04:04
Afr0
Yeah, it will.
I'm creating a dynamic page that will update itself based on which magazines are available (uploaded).
It used to be quite fast, but is now slower, because my boss insists on using flash to display magazines, meaning for every page request I have to unzip the flash data (slow) and generate a temporary html file with the flash data (fast).

Edit: I was hoping embedding Google Documents would make him satisfied, but he doesn't seem to think that it is 'intuitive'.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 30 Mar 2011, 04:15
JL235
You don't need to make temporary files. Just output all HTML for the page on the fly. That's the most efficient way to do it, regardless of if it's Flash or Google documents.

Btw I actually agree with your boss. Google documents isn't that great; a good Flash alternative (note: good) would be better.

There also shouldn't be any unzipping needed. Just paste the embed code and your done.
Wed, 30 Mar 2011, 04:51
Afr0
There also shouldn't be any unzipping needed.


Yes. The alternative would be to unzip when I'm done uploading, but that would increase the length of the uploading code. I'm also trying to keep folders clean and neat. I think I'm going to clean the temporary folder when index.php is requested. I haven't decided yet.

Also... I'm not sure I can output the HTML on the fly. If I've started to output the HTML for a page, can I start outputting some other HTML right on the fly?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 30 Mar 2011, 06:06
JL235
Afr0 Yes. The alternative would be to unzip when I'm done uploading

Then do that. Unzipping once is far more efficient then unzipping for each request. Lets say a magazine is read 10,000 times, then your files are unzipped 10,000 times!

Plus for 9,999 of those occasions it'll be overwriting the already unzipped files. Meaning that those 9,999 requests are pointless.

Alternatively, unpload your files non-zipped.

Afr0 Also... I'm not sure I can output the HTML on the fly. If I've started to output the HTML for a page, can I start outputting some other HTML right on the fly?

For that page, yes.

I suppose what you want is to be able to output for multiple pages? i.e. one for index, one for magazine_1, another for magazine_2 and so on.

A simple way to build this would be to have the magazine pages located at '/magazine/issue' where issue is the name or id of the magazine you want to read. You can then use your .htaccess file to point this to the index.php (so index.php is called when visiting both / and /magazine/issue). The code for this would be:


This means all pages (including /magazine/issue) now point to index.php.

At the top of index.php you then get the current url. If the url looks like '/magazine/issue' then it grabs the issue bit, uses the issue to find the magazine to show and then displays the magazine. Otherwise it will either output a 'magazine not found' page, a 404 page or output the front-page.

That's a simple way, but the proper way would be to get an MVC framework running and do all of the above properly. It'd be much more complex at first, but the code would scale much better. I'd highly advise this because websites rarely stop at one feature. It'll almost certainly grow and this will be easier to build if it's on top of a proper framework.

I recently worked on a site which heavily abused .htaccess and essentially had giant php scripts doing redirection (working out what to show next) randomly as they went. It was almost impossible to work on. In contrast MVC aims to be pretty much idiot proof since your just following the MVC structure (more bloated but idiot proof).

My personal recommendation would be to read the sections under 'General Topics' on the Code Igniter user guide. Even if you don't plan on using Code Igniter (or even an MVC architecture) it will give you ideas on how you could structutre the site.

Finally you normally don't echo large blocks of HTML in PHP. Instead you mix PHP and HTML using the PHP tags (<?php and ?>). Everything inside is PHP, everything outside is HTML (and is outmatically outputted to the user). For example here is some example code from PMC:

Notice that it's mostly HTML with bits of PHP dotted throughout.
Wed, 30 Mar 2011, 06:15
Afr0
Nevermind.
I found out I could pass the name of the current magazinefolder to another script using a querystring.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 30 Mar 2011, 06:32
JL235
If you do it my way you can keep the urls looking pretty.
Thu, 31 Mar 2011, 00:12
Afr0
Can anyone see any problems with this Javascript code, or the way I'm embedding it?



The Javascript code was generated by a program called AxMags for turning PDFs into Flash-books, and it seems to work fine enough on its own... but not when I'm embedding it!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 31 Mar 2011, 04:13
Afr0
Nevermind. I fixed it. For some reason it didn't like me using local names, so I had to use a full URL.



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 31 Mar 2011, 09:22
JL235
You don't need to use the full url, and I'd highly advise against this. It will break if you change the url or run it on a test server (like localhost).

I'm not fully sure, but I believe the problem is that you need a leading slash at the beginning of the url, like: '/tmpsites/magazine/main.swf' rather than 'tmpsites/magazine/main.swf'.