View Full Version : Uploading PDF and DOC files in PHP
04-27-2012, 11:32 PM
I want to know that if uploading PDF documents and DOC files in PHP is the same that you do when you code to upload images? I mean you just change the extension? And is it the same as you are saving an uploaded image in database? Thank you
04-27-2012, 11:43 PM
A file is a file. It doesn't matter if its text, image, or executable, the process is identical.
The extension is irrelevant, its only really a hint as to what the file should be, which may or may not represent what type of file it really is. Going from an image to a doc is better than going from a text to a different type in perspective of your SQL handling. If you deal with text only, its possible that the image is stored as a text type. If dealing with an image the field will be a blob type, or potentially a base64 representation of the text (not recommended due to the size, so more likely a blob). Since blobs are meant for binary data, it will be compatible with the doc so long as the field size is sufficient for the size of the file. So you should be good as gold when it comes to uploading no matter what you are doing for storage.
04-28-2012, 07:34 AM
Ok, if I understand well, the procedure is the same, thnak you for replyig me this. I have last thing to ask if you dont mind, suppose in my database, there are about 15000 records, and I want to display them on a page by implementing a pagination. About 20 records will be shown on a page, so the pagination page number will be more than 500 pages, it will be a problem on the page to have more than 500 in the pagination...do you have a solution how should I deal with this?
See this link of http://technorati.com/blogs/directory/overall/ Technorati, you have noticed the pagination below looks like this:
Page: 1 2 3 4 5 6 7 … 51976 Next »
It has three dots '...' after page 7, then show the whole number of blogs on the page, how to do that?
04-28-2012, 06:51 PM
Yes, that's a relatively simply task to do.
After counting the known number of records and knowing the number of page links you want to show, you can determine where the ... will go. This one in particular shows the first 7 pages, followed by . . . followed by (likely?) the last page.
I can't tell from this whether they show the first 7 pages, or if they show 3 pages on each side of the link. If this is on page 4, they are showing three on each side. If its on page 1 its 7. I'll assume its on page 4.
$iCurPage = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$iCurPage = $iCurPage <= 0 ? 1 : $iCurPage;
$iPagesShown = 3;
$iNumPages = 51976; // This would be calculated from total count / per page rounded up.
$iMinNumber = ($_min = $iCurPage - $iPagesShown) >= 1 ? $_min : 1;
$iMaxNumber = ($_max = $iCurPage + $iPagesShown) <= $iNumPages ? $_max : $iNumPages;
$aPages = range($iMinNumber, $iMaxNumber);
$sPageLinks = '';
// We'll just do something simple.
if (!in_array(1, $aPages))
$sPageLinks .= '<a href="?page=1">«First</a>';
if (min($aPages) > 1)
$sPageLinks .= '. . .';
foreach ($aPages AS $pageNum)
if ($pageNum != $iCurPage)
$sPageLinks .= sprintf('<a href="?page=%d" style="margin: 2px;">%d</a>', $pageNum, $pageNum);
$sPageLinks .= sprintf('<span id="currentPage">%d</span>', $pageNum);
if (max($aPages) < $iNumPages)
$sPageLinks .= '. . .';
if (!in_array($iNumPages, $aPages))
// This "last" link is actually the same as the 51976. You can show the $iNumPages instead of last
$sPageLinks .= sprintf('<a href="?page=%d">Last»</a>', $iNumPages);
Something simple like this. As indicated the first and last text is really the 1 and the last page number, so you can show that instead of the first and last if you want. Prev and next are also fairly easy to add, which I didn't do in this one.
A few years ago I wrote a pagination handling while learning a bit about the PHP OOP. It was designed as accepting wrapper classes for data so it would be usable in handling arrays, resultsets, whatever the wrapper is written for. It used function pointers to display the data, and did include how to handle situations as described like this.
Its a little out of date now though and my OOP skills in PHP have improved since, so eventually I'll rewrite that.
04-28-2012, 08:37 PM
Thank you for replying..I will consider your explanation by saving it.. If I meet some difficulties, can I contact you? Is there a method to you as friend on Coding forum? Or if you dont mind, I can add you on Facebook...
Im new in PHP, I mean started with it on December last year.. I already made some good websites with it and also secure, but I never made one with pagination etc... So, I am planning to make a website, I mean a port-folio, it can be true website late, but now, I am planning to make it on learning purpose. However, I am taking it as a true real-time website, so, I will place a lot of emphasis on it... It will either a website to make people upload fre PDF of their own writings, or a blog directory, or a business directory or any related website...
For example, let's assume it can be a log directory, so I will display everything in the table except ID (Primary key) on the page. And this can be 40 records per page. Assume thee will be 300,000 registered blog in the database, so it will be about 7500 pages in the pagination.. But assume, the number of blog registered exceed 5 millions, it will be a problem, so, I am planning that when it will exceed 7500 pages, it will go on another page to display the next 7500, same process if it exceeds 7500 pages again, display to another page until ends.. I dont want everything to com out at once, but prefer to break the number of pages i parts...
I have not yet started, I will tackle it on 11 June..