• Dear all,

    I have been trying to write a php program to upload a file from my C drive to the WordPress server. But I did not have any success so far.

    The W3Schools website published a piece of code based on the function move_uploaded_file, which assumes you uploaded a file already to a temporary location, and then move it to the location you wanted. What’s the use? But how could I upload it to the temporary place in the first place??

    Can anybody help? Thank you in advance.

    Salesian

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter salesian

    (@salesian)

    How can I specify the C drive location in my php program?

    Moderator bcworkz

    (@bcworkz)

    WordPress or PHP wouldn’t know anything about one’s local computer. They don’t all have C: drives. What is typically done is we’d serve a file upload field in a HTML form. The user would then specify the file they want uploaded in that field. When the form is submitted, the file is transferred to the server’s temporary folder. The browser and server handle this on their own, you needn’t do anything special. PHP can then move the file from temporary to where ever it’s appropriate.

    All you really need to do is serve an appropriate form, then move the file after the form had been submitted.

    Thread Starter salesian

    (@salesian)

    Thank you very much, bcworkz, for your reply.

    That’s good. So I would create a form with a filename field, then I’d specify the filename in that field. I believe the form would always passes a string to the server.

    Let’s suppose the filename is constant forever. If the filename is constant and the form always passes a string to the server, I can also hard-code the filename behind the form using php, so that the form would always passes a constant string to the server.

    My question is: how can I specify the filename behind the form? Is it something like this — C:/foldername/filename ?

    Moderator bcworkz

    (@bcworkz)

    Yes, use the local path to file as the field’s value. Just as it would be if you had gone through the file selection dialog to get it. It’d only be valid on your machine, but I suspect that’s your intent.

    Normally you’d still have to manually submit the form, but you could include a bit of JavaScript to do it for you after the page loads.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Uploading File using php’ is closed to new replies.