Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Upload File to Server

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Upload File to Server

Postby TedN » Sat Feb 23, 2013 8:27 pm

I would like to upload an Excel file from my PC to a server. I have found PHP code that requests the user to select the file then submit it.
However, I need to provide the file name directly (in code) and not via a request process.

In my Excel vba coding I can call an HTML file on the server using a hyperlink. My problem is how do I send the name and path of the Excel file to the HTML file, (as mentioned I need to avoid going through the file name request process).

Is there a way of including data (file name, etc) into the hyperlink that the HTML file can extract?

I'm really new at this server side coding so I don't even know if the above is possible.

Any help appreciated.
Thanks,
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Tue Feb 26, 2013 12:13 pm

It may be easier to map a drive to your server, and then save to the virtual drive, or look at vba ftp functions.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Wed Feb 27, 2013 1:25 pm

Thanks for the suggestion. I've tried mapping to the server without any luck. I'm waiting for a reply from my server provider to find out what I'm doing wrong.
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Wed Feb 27, 2013 1:37 pm

Just to make sure i'm understanding your intent correctly; you have an excel document for example, that you want the person to be able to save to the server etc, from within the document, right?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Thu Feb 28, 2013 7:42 pm

Yes, that is correct. I'm still having trouble mapping the drive. I use the Windows mapping wizard but I'm obviously putting in the wrong info.

I've progressed somewhat with another method. I have a PHP file on the server which will upload a file from my PC if the name of the file is passed to it. I can achieve this from an HTML file on my PC which requests the user to select the file and submit the file name. This prompts the PHP file to upload a file from the PC.

What I would like to do is change the HTML file so that it executes on load and not from a user request.

That's where I'm stuck right now. The HTML code that doesn't work is as follows:

Code: Select all
<html>
<head>
<title>test</title>

<script language="javascript">
    function MyFormSubmit(){
        document.myname.submit();
       //document.getElementById("myname").submit();
    }
</script>
</head>
<body onload="MyFormSubmit()">
<form action="http://myServer/upload.php" method="POST" name="myname" id="myname">
<input type="hidden" name="username" id="username" value="D:/Users/myPC/Desktop/NewFile.txt"></form>
</body>
</html>
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Fri Mar 01, 2013 8:38 am

just modify upload.php to respond to GET instead of POST, then you can pass the information through the url.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Fri Mar 01, 2013 2:35 pm

Unfortunately changing POST to GET didn't work either.
The HTML file does call the PHP file because I get the If statement message, "Sorry, there was a problem uploading your file."

For your info my PHP code is as follows:

Code: Select all
<?php
 $target = "uploads/";
 $target = $target . basename( $_FILES['uploaded']['name']) ;
 $ok=1;
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
 {
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
 }
 else {
 echo "Sorry, there was a problem uploading your file.";
 }
 ?>
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Fri Mar 01, 2013 2:43 pm

I am confident that i can help with this one, but will not be able to really commit any time to it before like monday :( sorry, am working right now and my weekend is kind of booked up. monday morning at the latest i should have a working script for you .
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Fri Mar 01, 2013 2:48 pm

Thank you Seandisanti. I look forward to seeing your solution. I've been messing around on this for several days now so a couple more won't hurt.


Thanks,
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Fri Mar 01, 2013 3:18 pm

Just for laughs in the interim, check out http://jream.com/learning/videos/php-ba ... e-handling to see if that helps. He's got a pretty good library of free instructional videos; that one is on file IO though, so would be best starting point i'd imagine.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Sun Mar 03, 2013 11:12 pm

I've been playing around with FTP and actually got it to work. I can now directly save my file to the web server. I'm still interested though in an HTML/PHP solution.
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby TedN » Wed Mar 06, 2013 8:28 am

Hi seandisanti,

Any luck with a PHP solution to automatic file uploading. I've given up with FTP, too inconsistent.
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Wed Mar 06, 2013 11:15 am

Inconsistent how? my implementation would just be ftp via php
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Wed Mar 06, 2013 3:58 pm

I set up FTP through the Windows Add Network Location wizard. Then I could see my server on my PC (Windows Explorer). I then added vba code in my Excel file so it would SaveAs on my server. Sometimes it worked other times nothing happened.
I'd be interested in your PHP solution.

Thanks,
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Thu Mar 07, 2013 1:57 pm

I'm sorry i've not had time to write up my own example, but here is another tutorial that shows ftp functions in use:

http://davidwalsh.name/send-files-ftp-php
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Upload File to Server

Postby TedN » Fri Mar 08, 2013 11:08 pm

Thanks for the link. It looks interesting. I'll check it out.
TedN
New php-forum User
New php-forum User
 
Posts: 11
Joined: Sat Feb 23, 2013 8:00 pm

Re: Upload File to Server

Postby seandisanti » Mon Mar 11, 2013 7:27 am

no problem, I'm glad to help
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron