Upload File to Server
Moderators: egami, macek, gesf
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,
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,
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 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.
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 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?
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:
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>
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
just modify upload.php to respond to GET instead of POST, then you can pass the information through the url.
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:
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.";
}
?>
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 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 .

-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 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.
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
Inconsistent how? my implementation would just be ftp via php
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,
I'd be interested in your PHP solution.
Thanks,
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 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
http://davidwalsh.name/send-files-ftp-php
-
- php-forum Fan User
- Posts: 973
- Joined: Mon Oct 01, 2012 12:32 pm
no problem, I'm glad to help