Forum Moderators: coopster
$uploaddir = '/home/your_path/public_html/images/';
if (move_uploaded_file($_FILES['pic']['tmp_name'], $uploaddir . $new_pic)) {
} else {
print File did not upload!";
}
My first question is can I literally put "['tmp_name']" in the if station or is that supposed to refer to my specific temp directory that might differ from user to user.
Secondly, I think the path of my directory might be the problem. I think I may not be using a valid directory for my $uploaddir variable, though I know it exists, as it is where I keep all my individual php files which I have no problem calling. I'm developing my website on a computer that is not connected to the internet and am running apache on it. If I view my development pages with my browser at _ttp://localhost/folder1/folder2/page.php
and the actual files reside in
c:/apache/htdocs/folder1/folder2/page.php.
I want the uploaded files to reside in
c:/apache/htdocs/folder1/folder2/folder3
So, what should $uploaddir be in my example?
Sorry for the long post, but any help is much appreciated.
Yes, and as a matter of fact, you must. PHP creates an associative array of items uploaded to the current script via the HTTP POST method and places them in a superglobal named $_FILES. The index you are referring to must be specifically named as such.
>>So, what should $uploaddir be in my example?
$uploaddir = 'c:/apache/htdocs/folder1/folder2/folder3';
Resource:
Handling file uploads [php.net]
upload_tmp_dir
Don't forget to create the directory first, and give it the necessary NTFS permissions if your volume is using the NTFS format.
This directory can be the same for different users because the files don't stay there.
Other settings in php.ini that can affect your uploads:
file_uploads
upload_max_filesize
post_max_size
max_input_time
There's a good explanation of file uploading in the book "PHP and MySQL Web Development, 2nd Ed.," Chapter 16. You can download the code from the book at the publisher's web site, [samspublishing.com...]
See also the online PHP Manual, Chapter 18, at www.php.net.
BTW, in specifying the final upload directory in a PHP script specifying a Windows directory, one way that works is as follows:
$uploaddir="C:\\Apache\\htdocs\\uploads\\";