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.
Not a member yet? Click here to register.
Forgot Password?

Help With Custom Coding

Asked Modified Viewed 1,156 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

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:
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.
0 replies

4 posts

G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

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?
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

Edited by Chan on 19-08-2019 09:57,
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

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:
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.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

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 !!!
Edited by Grimloch on 20-08-2019 07:11,
0 replies

Category Forum

Panels and Infusions

Labels

None yet

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet