Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Help With Custom Coding

Scenario: a download folder in my infusion contains a recently uploaded epub file.
Folder: "downloads/filename.epub" uploaded epub file
Folder: "books/book_title/extracted contents of epub file" uploaded manually after changing epub file to zip file and extracting.
Folder: "ereader/book_title.php" script to READ epub files on server in the browser.

After epub file and image are uploaded and the info is written into the db table I do this:
CodeDownload  
if (!is_dir(MY_BOOKS.$book_title)) {
 @mkdir(MY_BOOKS.$book_title, 0755, true);
}
if (!is_file(READER.$book_title.".php")) {
 $my_file = fopen(READER.$book_title.".php", 'w');
 $my_data = file_get_contents(INFUSIONS."booklib/admin/prototype.txt");
 fwrite($my_file, $my_data);
 fclose($my_file);
 $fname = (READER.$book_title.".php");
 $new_file = fopen($fname, 'r');
 $content = fread($new_file,filesize($fname));
 $content = str_replace('NEW_TITLE', $book_title, $content);
 $fhandle = fopen($fname,'w');
 fwrite($fhandle,$content);
 fclose($fhandle);
}


This works exceptionally well; I get a directory created with the book title as name. I get a script file created in the "ereader" directory. All is good. But then I have to manually upload the extracted epub(zip) into the "books/book_title" directory. But this is what I would like to do.
I need to copy the uploaded file into the books/book_title directory renaming it to filename.zip; then extract that file on the server then delete the copied zip file. The reason for all of this is that the open source epub reader I found and am using can't handle the epub file as is but must read the extracted files.
OK. I made progress. The uploaded file is now copied into the correct directory but with an epub extension. How do I now change the file extension to a zip, unzip it in the same directory and then delete the zip file?
Yes I know. But before I can use that I need to successfully change the file extension to ".zip" and so far I can't make it work. Here's what I have:
CodeDownload  
if (!is_dir(MY_BOOKS.$book_title)) {
 @mkdir(MY_BOOKS.$book_title, 0755, true);
 $src_file = BOOKS.$book_file;
 copy($src_file, MY_BOOKS.$book_title.'/'.$book_file);
 $file = (MY_BOOKS.$book_title.'/'.$book_file);
 substr_replace($file , 'zip', strrpos($file , '.') +1);
}


If I could just get the extension to change then I could proceed to learn how to unzip it and then delete the zip file.
Fantastic !!! Using php's ZIP class I was able to extract the epub file to the directory w/o need to change the extension to .zip ! All is well except for deleting the epub file in the directory where it's extracted. I've read that UNLINK will only accept a PATH and not a url. I'm not sure about that and will have to experiment further. cool

Added Note: I figured out how to use the UNLINK command. All is good the infusion is now complete. After extraction the epub file in the target directory is now deleted; NO ERRORS !!!
Thread Information
Author
Replies
5 posts
Views
132 times
Last Post
Last updated on 1 month ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Chan, Grimloch