Forum Moderators: coopster

Message Too Old, No Replies

help with uploading files

         

associates

5:38 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Hi,

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.

RonPK

8:28 am on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the script running on //fileserver or somewhere else? AFAIK, it has to be on the same server.

associates

12:02 am on Oct 6, 2005 (gmt 0)

10+ Year Member



Hi, Thank you for your reply. The script is written and run on my laptop which is also part of the network as the fileserver. I am not sure if this is to do with the move_uploaded_file(...).

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.

RonPK

9:14 am on Oct 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think you can use move_uploaded_file() to move the file to a different server. The function is made to move the uploaded file from its temporary location to a directory of your choice on the same server.

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.