Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Open a file from server

Open a file from server

Scheduled Pinned Locked Moved Web Development
questionphphtmldatabasecom
30 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hiral_shah
    wrote on last edited by
    #1

    Hi there, I am passing following in html: associatedText now on clicking on associatedText I am getting uploadId in php and from that I am fetching server Path that is stored in database. suppose my server path = "ftp://userName:Password@ftp.example.com/TempUpload/Doc/Case Studies for Uploading.doc" this is giving me not readable result of the file. Can you please tell me how can I open the file in readable manner??

    B 1 Reply Last reply
    0
    • H hiral_shah

      Hi there, I am passing following in html: associatedText now on clicking on associatedText I am getting uploadId in php and from that I am fetching server Path that is stored in database. suppose my server path = "ftp://userName:Password@ftp.example.com/TempUpload/Doc/Case Studies for Uploading.doc" this is giving me not readable result of the file. Can you please tell me how can I open the file in readable manner??

      B Offline
      B Offline
      Bradml
      wrote on last edited by
      #2

      So is the problem that you cannot read the file from the FTP server?


      Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

      H 1 Reply Last reply
      0
      • B Bradml

        So is the problem that you cannot read the file from the FTP server?


        Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

        H Offline
        H Offline
        hiral_shah
        wrote on last edited by
        #3

        No I got the file in the same browser with not readable fonts that are like square, circle etc. But I want the same file in open another browser with the same formating that has been in the file located at the server.

        B 1 Reply Last reply
        0
        • H hiral_shah

          No I got the file in the same browser with not readable fonts that are like square, circle etc. But I want the same file in open another browser with the same formating that has been in the file located at the server.

          B Offline
          B Offline
          Bradml
          wrote on last edited by
          #4

          If i understand correctly you want them to be able to, say, have the "save file" dialog pop up. If so you want:

          header('Content-Disposition: attachment; filename="[FILE NAME]"');


          Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

          H 1 Reply Last reply
          0
          • B Bradml

            If i understand correctly you want them to be able to, say, have the "save file" dialog pop up. If so you want:

            header('Content-Disposition: attachment; filename="[FILE NAME]"');


            Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

            H Offline
            H Offline
            hiral_shah
            wrote on last edited by
            #5

            No dear, I want just the file from the server that is only readable. the user can not save it directly. suppose there is a ".doc" file and the user click on it's link then he should read the content of that file from the window itself.

            B 1 Reply Last reply
            0
            • H hiral_shah

              No dear, I want just the file from the server that is only readable. the user can not save it directly. suppose there is a ".doc" file and the user click on it's link then he should read the content of that file from the window itself.

              B Offline
              B Offline
              Bradml
              wrote on last edited by
              #6

              Then you are going to need the "Content-type: [content type]" header. You can get the value when it is first uploaded:

              $fileType = $_FILES['NAME']['type'];

              //This is an example of using this value.

              str_replace("\n", "", $fileType); //Security
              str_replace("\r", "", $fileType); //Security

              header("Content-type: {$fileType}"); //Send Header

              echo $File; //Echo the file down.


              Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

              H 1 Reply Last reply
              0
              • B Bradml

                Then you are going to need the "Content-type: [content type]" header. You can get the value when it is first uploaded:

                $fileType = $_FILES['NAME']['type'];

                //This is an example of using this value.

                str_replace("\n", "", $fileType); //Security
                str_replace("\r", "", $fileType); //Security

                header("Content-type: {$fileType}"); //Send Header

                echo $File; //Echo the file down.


                Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                H Offline
                H Offline
                hiral_shah
                wrote on last edited by
                #7

                Hi, Actually what I am doing is: 1> The user will upload a file to the server 2> I am storing that file information like, server path with file name and extension, associated text(show to the user by clicking on which it will show the file on that path that is stored for that text) 3> Now the another user wants to open that uploaded file so he will search by associated text and will get some link with them. 4> Now when he will click on some associated text, the path for that text will be there and the file should display over there or in another window to that user. upto 3rd point is working properly but 4th point is not. Hope you can get better idea from this what I want to do. I am waiting for your reply.:)

                B 1 Reply Last reply
                0
                • H hiral_shah

                  Hi, Actually what I am doing is: 1> The user will upload a file to the server 2> I am storing that file information like, server path with file name and extension, associated text(show to the user by clicking on which it will show the file on that path that is stored for that text) 3> Now the another user wants to open that uploaded file so he will search by associated text and will get some link with them. 4> Now when he will click on some associated text, the path for that text will be there and the file should display over there or in another window to that user. upto 3rd point is working properly but 4th point is not. Hope you can get better idea from this what I want to do. I am waiting for your reply.:)

                  B Offline
                  B Offline
                  Bradml
                  wrote on last edited by
                  #8

                  Hmm, well when they file is uploaded could you not store the file type when they upload it?


                  Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                  H 1 Reply Last reply
                  0
                  • B Bradml

                    Hmm, well when they file is uploaded could you not store the file type when they upload it?


                    Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                    H Offline
                    H Offline
                    hiral_shah
                    wrote on last edited by
                    #9

                    well I can store the type too.

                    B 1 Reply Last reply
                    0
                    • H hiral_shah

                      well I can store the type too.

                      B Offline
                      B Offline
                      Bradml
                      wrote on last edited by
                      #10

                      Wit, now i think i know what the problem is: is it that you don't know how to get the file for the user?


                      Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                      H 2 Replies Last reply
                      0
                      • B Bradml

                        Wit, now i think i know what the problem is: is it that you don't know how to get the file for the user?


                        Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                        H Offline
                        H Offline
                        hiral_shah
                        wrote on last edited by
                        #11

                        :-D You got the problem that I am having

                        1 Reply Last reply
                        0
                        • B Bradml

                          Wit, now i think i know what the problem is: is it that you don't know how to get the file for the user?


                          Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                          H Offline
                          H Offline
                          hiral_shah
                          wrote on last edited by
                          #12

                          Have you any idea how can I get the file from server and show it to the user as per its format???

                          B 1 Reply Last reply
                          0
                          • H hiral_shah

                            Have you any idea how can I get the file from server and show it to the user as per its format???

                            B Offline
                            B Offline
                            Bradml
                            wrote on last edited by
                            #13

                            Ok do you mean just send it to them as if they have requested it from the server normally or do you mean in a way that the browser will save it to disk?


                            Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                            H 1 Reply Last reply
                            0
                            • B Bradml

                              Ok do you mean just send it to them as if they have requested it from the server normally or do you mean in a way that the browser will save it to disk?


                              Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                              H Offline
                              H Offline
                              hiral_shah
                              wrote on last edited by
                              #14

                              I want that dialogbox that will ask the user to save or open the file he is asking for. The dialogbox that is appears for normally we are downloading some attachment from the mail which asking to open file temporary or want to save it.

                              B 1 Reply Last reply
                              0
                              • H hiral_shah

                                I want that dialogbox that will ask the user to save or open the file he is asking for. The dialogbox that is appears for normally we are downloading some attachment from the mail which asking to open file temporary or want to save it.

                                B Offline
                                B Offline
                                Bradml
                                wrote on last edited by
                                #15

                                The code I gave you before (Content-disposition) will do that for you.


                                Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                                H 1 Reply Last reply
                                0
                                • B Bradml

                                  The code I gave you before (Content-disposition) will do that for you.


                                  Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                                  H Offline
                                  H Offline
                                  hiral_shah
                                  wrote on last edited by
                                  #16

                                  Its give me an error "Warning: Cannot modify header information - headers already sent" on following line, header("Content-type: {$fileType}"); do you have any alternative??

                                  B 1 Reply Last reply
                                  0
                                  • H hiral_shah

                                    Its give me an error "Warning: Cannot modify header information - headers already sent" on following line, header("Content-type: {$fileType}"); do you have any alternative??

                                    B Offline
                                    B Offline
                                    Bradml
                                    wrote on last edited by
                                    #17

                                    Ok this error is because you have not started the document with the <?php tag. Although this is a common mistake it is made by many people. Make sure there is no blank space in the file before the php tag and make sure that you don't echo or print anything to the browser before the header function executes.


                                    Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                                    H 1 Reply Last reply
                                    0
                                    • B Bradml

                                      Ok this error is because you have not started the document with the <?php tag. Although this is a common mistake it is made by many people. Make sure there is no blank space in the file before the php tag and make sure that you don't echo or print anything to the browser before the header function executes.


                                      Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.

                                      H Offline
                                      H Offline
                                      hiral_shah
                                      wrote on last edited by
                                      #18

                                      Well I have used only one php file for the whole application So php tags are there as per they should. I just use cases for doing different things. I wrote : associatedText And there is no echo after the linked text is clicked.

                                      B 2 Replies Last reply
                                      0
                                      • H hiral_shah

                                        Well I have used only one php file for the whole application So php tags are there as per they should. I just use cases for doing different things. I wrote : associatedText And there is no echo after the linked text is clicked.

                                        B Offline
                                        B Offline
                                        Bradml
                                        wrote on last edited by
                                        #19

                                        can you please email me the source code so i can see what is going on.


                                        Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                                        B 1 Reply Last reply
                                        0
                                        • B Bradml

                                          can you please email me the source code so i can see what is going on.


                                          Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                                          B Offline
                                          B Offline
                                          Bradml
                                          wrote on last edited by
                                          #20

                                          OK two problems that jump out at me from the scripts you sent is that you have a character before the first tag in the library and also you have a blank line at the end of it. Because of this it will send all headers down before you can modify them.


                                          Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups