Uploading a pre-defined filename to a server with PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I am a complete novice but would liket to have a PHP script which will
upload a file which is pre-defined, without the need for the user to
'Browse' for a file path. For example, the pre-defined file would be
"C:\temp\test.txt", and the script will already know this value
without the user telling it.

I tried filling the textbox with a file path value, but it doesn't
work with the input type "file", only as a "textbox". So I am now
certain that the PHP code is the only way to maybe solve it, and
hoping someone can help me

Here's the HTML code:

<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" />


And here's the PHP code:


$uploaddir = '/home/vhosts/seanlock.275mb.com/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';a
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';

print "</pre>";


If anyone knows of a simple way of achieving what I'm after, I'd be
really grateful for any help.


Re: Uploading a pre-defined filename to a server with PHP


Quoted text here. Click to load it

 Can't. It's a browser limitation for security reasons.

 See also: http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.10.1

 Whilst the standard recommends prompting for confirmation, most browsers err
on the side of caution and simply ignore the value attribute.

 More: http://www.cs.tut.fi/~jkorpela/forms/file.html

Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Site Timeline