Forum Moderators: coopster

Message Too Old, No Replies

user uploads a file

and php puts it in the right spot?

         

coolo

5:35 am on Mar 1, 2004 (gmt 0)

10+ Year Member



ok, I'm having issues trying to allow users to upload files through a webpage. I've read thread 777 and I've got most of everything down. My specific problem, (I'm pretty sure) is with the following piece of script(taken from thread 777).

$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.

coopster

12:02 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>My first question is can I literally put "['tmp_name']" ...

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]

chgoweb

5:40 am on Mar 2, 2004 (gmt 0)

10+ Year Member



You need a temporary directory for the uploads to go to before you move them to their final destination using move_uploaded_file(). The temporary directory can be specified in php.ini using:

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\\";

coolo

5:14 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



hey thanks for the help. I got this one figured out now. On to the next question...