Re: [PHP] move_uploaded_file() does not return any value or warning

2011-10-14 Thread Partha Chowdhury

On 15/10/11 08:35 AM, Simon J Welsh wrote:
Assuming you did $move_uploaded_file = move_uploaded_file($filename, 
$destination);, then isset($move_uploaded_file) will always be true. 
isset() just checks if the variable you past to it is set, not if it 
has a non-false value. You could simply use 
if(move_uploaded_file($filename, $destination)), or 
if($move_uploaded_file). 
My apologies - i forgot to include the $move_uploaded_file = 
move_uploaded_file($filename, $destination); line.


I saw in the manual that isset() "isset --- Determine if a variable is 
set and is not NULL" and thought if move_uploaded_file() returns false, 
the error checking will be triggered.But now i see the sample code in 
the manual and stand corrected.


So what was happening that $move_uploaded_file was set but empty.My 
understanding of isset() was wrong.


*
*





Re: [PHP] move_uploaded_file() does not return any value or warning

2011-10-14 Thread Simon J Welsh
On 15/10/2011, at 4:01 PM, Partha Chowdhury wrote:

> Then i set a check for the return value of move-uploaded_file.
>> if(isset ($move_uploaded_file)):
>>   echo ""success;
>>   else:
>>   echo "error in uploading";
>>   endif;
> But it does not print anything !

Assuming you did $move_uploaded_file = move_uploaded_file($filename, 
$destination);, then isset($move_uploaded_file) will always be true.

isset() just checks if the variable you past to it is set, not if it has a 
non-false value. You could simply use if(move_uploaded_file($filename, 
$destination)), or if($move_uploaded_file).
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] move_uploaded_file() does not return any value or warning

2011-10-14 Thread Partha Chowdhury

Hello List.

I am learning php and MySQL for my project work.

I am trying to upload files to local server.

First, a page is displayed on the browser to upload file

Relevant code:







After the user chooses a file and hit the submit button,the browser 
displays the content from the "uploads" directory.


Php code:


$destination = "uploads/" . time() . "_-" . 
$_FILES['file']['name'];



  move_uploaded_file($filename, $destination);
header("Location:uploads/");

But the uploads directory is empty and no warning or error is displayed !

Then i set a check for the return value of move-uploaded_file.

if(isset ($move_uploaded_file)):
   echo ""success;
   else:
   echo "error in uploading";
   endif;

But it does not print anything ! .According to manual,


Returns *TRUE* on success.

If /filename/ is not a valid upload file, then no action will occur, 
and *move_uploaded_file()* will return *FALSE*.


If /filename/ is a valid upload file, but cannot be moved for some 
reason, no action will occur, and *move_uploaded_file()* will return 
*FALSE*. Additionally, a warning will be issued.



So the above code should have printed "error in uploading".
Then i tried the copy() function and it prints a warning:

*Warning*: copy() [function.copy 
]: Filename cannot be 
empty in */srv/www/htdocs/file_uploading/index.php* on line *38*

line 38 is


copy($filename, $destination);
Then i did a print_r($_FILES['file']) and found that 
$_FILES['file']['error'] was 1 .The problem was the file i was trying to 
upload was 6M in size,greater than upload_max_filesize in /etc/php.ini 
which was 2M.I changed that and now it works.


So I want to know - does move_uploaded_file returns false on failure or 
is there a bug in my code ?


I am using php 5.3.8 which is configured with

'./configure' '--prefix=/php' '--with-apxs2=/apache/bin/apxs' 
'--with-config-file-path=/etc' '--with-mysql-sock=/tmp/mysql.sock' 
'--with-openssl' '--with-zlib' '--enable-bcmath' '--with-bz2' 
'--enable-calendar' '--with-gdbm' '--with-enchant' '--enable-exif' 
'--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-gettext' 
'--with-gmp' '--enable-mbstring' '--with-mcrypt' '--with-readline' 
'--enable-soap' '--enable-sqlite-utf8' '--enable-zip' 
'--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' 
'--with-jpeg-dir=/usr/lib' '--with-freetype-dir'
and error_reporting directive in php.ini is "error_reporting = E_ALL | 
E_STRICT".