LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP file uploads problem ... (https://www.linuxquestions.org/questions/programming-9/php-file-uploads-problem-259416/)

MikeFoo1 11-26-2004 02:02 AM

PHP file uploads problem ...
 
Hi all,

i am learning php and have a small problem with uploading files.


Here is what i have :
Code:

          $uploadDir="/home/mike/www/uploads/";
        $uploadFile=$uploadDir.basename($_FILES["userfile"]["name"]);

        if(is_uploaded_file($uploadFile))
                print($_FILES["userfile"]["name"]." has been uploaded ! <br/>");
        else
                print("Not uploaded ! <br/>");

        print("Name :".$_FILES["userfile"]["tmp_name"]. "<br/>");
        print("Error code :".$_FILES["userfile"]["error"]. "<br/>");

        print_r($_FILES);

The result i get :

Not uploaded !
Name :/home/mike/www/uploads/phpMJsUbD
Error code :0 <------------------------------- error code is ok .
Array ( [userfile] => Array ( [name] => cv.txt [type] => text/plain [tmp_name] => /home/mike/www/uploads/phpMJsUbD [error] => 0 [size] => 808 ) )


My php.ini file looks like this :

;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "/home/mike/www/uploads" <-------------------------------------

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M



Cant see any files in the upload directory ;(.Anyone ?

sigsegv 11-26-2004 03:07 AM

I can tell you've been there already, but go read it again. The php.net doc on dealing with file uploads covers exactly what you're trynig to do.

You're biggest problem here though is that you're checking $_FILES["userfile"]["name"] with is_uploaded_file, and then printing $_FILES["userfile"]["tmp_name"]. If you want to check existance of $_FILES["userfile"]["name"], you have to copy() $_FILES["userfile"]["tmp_name"] to $_FILES["userfile"]["name"].

ner0 11-26-2004 06:41 AM

move_uploaded_files would also produce the same results

MikeFoo1 11-26-2004 02:53 PM

Quote:

Originally posted by sigsegv
I can tell you've been there already, but go read it again. The php.net doc on dealing with file uploads covers exactly what you're trynig to do.

You're biggest problem here though is that you're checking $_FILES["userfile"]["name"] with is_uploaded_file, and then printing $_FILES["userfile"]["tmp_name"]. If you want to check existance of $_FILES["userfile"]["name"], you have to copy() $_FILES["userfile"]["tmp_name"] to $_FILES["userfile"]["name"].


Yeah , i have got it now .Thanks :-).


All times are GMT -5. The time now is 08:37 PM.