LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2004, 02:02 AM   #1
MikeFoo1
Member
 
Registered: Apr 2004
Distribution: Slackware 9.1
Posts: 72

Rep: Reputation: 15
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 ?
 
Old 11-26-2004, 03:07 AM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
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"].
 
Old 11-26-2004, 06:41 AM   #3
ner0
LQ Newbie
 
Registered: Jun 2004
Posts: 18

Rep: Reputation: 0
move_uploaded_files would also produce the same results
 
Old 11-26-2004, 02:53 PM   #4
MikeFoo1
Member
 
Registered: Apr 2004
Distribution: Slackware 9.1
Posts: 72

Original Poster
Rep: Reputation: 15
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 :-).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vsftp large file uploads fail randybell Linux - Newbie 2 09-28-2004 10:17 PM
Uploads stall after some kB (modem). Firewall-Problem? furryspider Linux - Networking 2 07-30-2004 12:25 PM
Problem when using crontab to execute a .php file doublesheep Linux - General 3 06-10-2004 08:46 AM
php.ini and file uploads gblue Linux - Newbie 0 02-29-2004 05:28 PM
PHP: simplest way to limit uploads to upload directory J_Szucs Programming 3 11-11-2003 02:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration