Jump to content

Recommended Posts

Hi.

I'm trying to create a small script for personal use. The scope is to upload automatically a certain txt file from my PC hard drive to my server (in a certain directory) every time the script is running.

 

I try different ways (ftp upload using "ftp_put" command, trying to "get_file_contents", etc.) but i always have the same problem: the error i get is that "No such file or directory".

This error is about the file on my local PC hard drive.

I know that most browser for security reasons doesn't allow access to files from local PC hard drive.

Is this the reason i fail miserably or there is a mistake when a declare the local (PC hard drive) path.

Until now i try:

c:\directory\subdurectory\filename.txt
c:/directory/subdurectory/filename.txt
file:///c:\directory\subdurectory\filename.txt
file:///c:/directory/subdurectory/filename.txt

every time without succes.

 

Any ideas?

 

Thank you in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/301269-upload-file-from-local-pc-to-server/
Share on other sites

Are you writing a command line php program that you are running from a CMD shell?

 

That would be the ideal way to do something like this.  If not you would have to be running within the environment of some sort of webserver, and that is not what you want to do for an automation utility.

 

This page covers the basics of this:  http://php.net/manual/en/install.windows.commandline.php

 

You want to specify the path to the php interpreter in your windows and the path to your script, for example:

C:\PHP5\php.exe -f "drive:/path/to/your/script.php"

Once this runs natively, you can tweak your windows environment if you want to associate command line php with .php file extension scripts etc. if you choose.

Thank you for your answers.

 

@requinix

No. I try to check the file size and i get error:  "filesize(): stat failed"

I try to run a script on my server from a browser, so maybe the problem is what i thought in the first place.

I read somewhere that browsers block the access on local files, when you try to access them from a remote server (the internet)

 

@gizmola

As i mention above i try to run the script located on my internet server via a browser.

I don't run the script on my computer so the source you mention in not relevant in my case.

you cannot automatically upload a file from the client/local pc to a remote server using a script running on the remote server, without having some software running on the client/local pc. the script running on the remote server does not have any access to the files on the client/local pc, either through the browser or via any communication protocol.

 

to do this, you first need to pick a protocol. ftp, http, or ssh would be the available choices. you would then need to install server software on the client/local pc, either an ftp server, a http server, or an ssh server. you could then have a script running on the remote server connect to the client/local pc and upload/copy the file.

actually, there may (untested) be a way to do this through the browser.

 

at least the chrome browser, has a command line parameter that allows local file access. it's intended to allow local testing, where things like an ajax request would make use of a local file. when used, this applies to any url the browser requests, so you would only want to do this for your site, so as to not allow any other site access to files on the local pc. you would make a desk-top short-cut that invokes the browser with the correct command line parameter and only use this when visiting your site.

 

i don't know if the 'same origin' policy would override this, since the web page is coming from a different address than the local usage in the code.

 

assuming all this actually works, the client-side code on the page could make an ajax request to read the local file, then submit the data to the remote server in a post request.

 

this sounds like a good phpfreaks programming challenge to see if anyone can come up with working code and for which browsers it would work.

Edited by mac_gyver
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.