File Upload Issue
Posted: Sat Mar 06, 2010 12:18 pm
Hi everyone, firstly I would like to say Im newbie to PHP and am already experiencing my first issues!
What I am trying to do is upload a file to the same location as the script.
For some odd reason I cannot transfer the file to the script location, here is the code, maybe I am doing something wrong.
<?php
$uploaddir = './';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
}
else
{
echo "Does not work!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
My output on the page returned is:
Does not work!
Here is some more debugging info:Array
(
[uploadedfile] => Array
(
[name] => qryClientLicences.csv
[type] => application/vnd.ms-excel
[tmp_name] => /tmp/phpTC2Ij3
[error] => 0
[size] => 108
)
)
Also, I need to restrict it to only CSV files, how do I do this?
My server PHP and MySQL versions are as follows:
Server: Localhost via UNIX socket
Server version: 5.0.89-community
Protocol version: 10
MySQL client version: 4.1.22
PHP extension: mysql
What I am trying to do is upload a file to the same location as the script.
For some odd reason I cannot transfer the file to the script location, here is the code, maybe I am doing something wrong.
<?php
$uploaddir = './';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
}
else
{
echo "Does not work!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
My output on the page returned is:
Does not work!
Here is some more debugging info:Array
(
[uploadedfile] => Array
(
[name] => qryClientLicences.csv
[type] => application/vnd.ms-excel
[tmp_name] => /tmp/phpTC2Ij3
[error] => 0
[size] => 108
)
)
Also, I need to restrict it to only CSV files, how do I do this?
My server PHP and MySQL versions are as follows:
Server: Localhost via UNIX socket
Server version: 5.0.89-community
Protocol version: 10
MySQL client version: 4.1.22
PHP extension: mysql