Forum Moderators: coopster
I have a quick question on how to get around this problem. Honestly, this is my first attempt to upload files from my computer to the fileserver. My computer and fileserver are sitting on the same network. What i'm trying to do is to upload a dummy.doc from my laptop to the fileserver. I've been to the PHP website and got question to ask.
Here is the code.
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
And on the upload.php file, i have the following code;
<?php
$uploadDir = '/var/www/uploads/';
$uploadFile = $uploadDir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
{
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:\n";
print_r($_FILES);
}
else
{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";
?>
I replaced $uploadDir = '/var/www/uploads/' to $uploadDir = '//fileserver/myshareddocs/upload' because that's the location i want to upload the files to on the fileserver.
Then, after selecting the file i want and click the upload button, all i can see from the upload.php page is
Possible file upload attack!
Here is some more debugging info:Array
(
)
What else should i change apart from replacing the $uploadDir variable?
Thank you very much in advance and look forward to hearing from you.
Can i ask a silly question?
The following code:
$uploadDir = '//fileserver/myshareddocs/upload'
Q1: Is this the directory where the uploaded file will be placed onto?
Q2: Not sure if i use the right slashes. "// or just / or \\ or \. Anyway, i can try this later but the thing is not sure which one is the problem here?
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))
Q1: is that mean the uploaded file will be moved to the upload folder and saved as 'tmp_name'?
Thank you once again and look forward to hearing from you.
You'll probably need to call some system command to copy the moved file to the other server, using exec() or a related PHP function. exec("copy $uploadFile //fileserver/foo/bar.ext"), in pseudo code. The exact command of course depends on your OS.