File Upload Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
milks77
Forum Newbie
Posts: 1
Joined: Sat Mar 06, 2010 12:08 pm

File Upload Issue

Post by milks77 »

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
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: File Upload Issue

Post by davex »

Does your PHP script have write access to that directory?

Usually the script runs as "apache" (on Linux/Unix) so you would normally need a globally writeable directory.

Try just having a script do an fopen("somefile.txt","w"); to see if it can open a file to write to in that dir.

Cheers,

Dave.
Post Reply