weird uploading file

This is a discussion on "weird uploading file" within the PHP Forum section. This forum, and the thread "weird uploading file are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 18th, 2007, 19:22
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
weird uploading file

Hi,

I was uploading a very small text file (sqltext.txt)from a folder(A) and try to copy it to the another folder(B)where is the same folder with the fileupload.php and file_upload.html. After uploading the sqltext.txt, the browser displays nothing, neither a error message nor any message. Not sure what happened? Would you mind helping me for this problem? Any inputs will be much appreciated!!!
HTML: Select all
<form name="form1" method="post" enctype="multipart/form-data" action="fileupload.php">
    <p>Name:<input type="text" name="uname" /></p>
    <p>Choose file you want to upload:</p>
    <p><input type="file" name="ufile" /></p>
    <p><input type="submit" name="submit" value="Start to Upload" /><input name="reset" type="reset" value="Reset" /></p>
</form>
PHP: Select all

<?php
//receiving uploaded file from client side
echo $_POST['uname']. " Hello:<p>";
$error_msg=$_FILES['ufile']['error'];
$fname=$_FILES['ufile']['name'];
$tmpname=$_FILES[['ufile']['tmp_name'];
$fsize=$_FILES['ufile']['size'];
$ftype=$_FILES['ufile']['type'];

//if to determining file be successfully uploaded
    
if($error_msg){
        echo 
"<font color='red'> File has not been uploaded successfully!</font><p>";
        echo 
"The relevanted error is: ".$error_msg;
    }else{
        
//file uploaded successfully
        
echo "Already received uploaded file, file name is: ".$fname."<br>";
        echo 
"File name is the server position as temp is: ".$tmpname."<br>";
        echo 
"Uploaded file size is: ".$fsize."<br>";
        echo 
"Uploaded file type is: ".$ftype."<br>";
        echo 
"<hr>";
        
        
//save the uploaded file to the respective folder
        
$success=copy($tmpname,'newtext.txt');
        
        if(
$success){
            echo 
"File has been copied successfully<br>";
            echo 
"New file path and directory name is below: <br>";
            echo 
realpath('newtext.txt')."<p>";
            
        
//delete this uploaded file
        
unlink($tmpname);
        }else{
        
            echo 
"<font color='red'>Can not copy this file !</font>";
        }
    
    }
?>
Reply With Quote

  #2 (permalink)  
Old Sep 18th, 2007, 19:53
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: weird uploading file

Can you check your error log to see if there is any PHP error occurring.

Also a few hints

It is is much more secure to use is_uploaded_file() and move_uploaded_file() in PHP.

So you could change your code to be

PHP: Select all

<?php

//receiving uploaded file from client side
echo $_POST['uname']. " Hello:<p>";
$error_msg=$_FILES['ufile']['error'];
$fname=$_FILES['ufile']['name'];
$tmpname=$_FILES[['ufile']['tmp_name'];
$fsize=$_FILES['ufile']['size'];
$ftype=$_FILES['ufile']['type'];

//if to determining file be successfully uploaded
// Is uploaded file makes sure that the file was uploaded and not a user trying to use HTTP tricks to work with files it shouldn't
    
if(!is_uploaded_file($fname)){
        echo 
"<font color='red'> File has not been uploaded successfully!</font><p>";
        if (
$error_msg)
        echo 
"The relevanted error is: ".$error_msg;
    }else{
        
//file uploaded successfully
        
echo "Already received uploaded file, file name is: ".$fname."<br>";
        echo 
"File name is the server position as temp is: ".$tmpname."<br>";
        echo 
"Uploaded file size is: ".$fsize."<br>";
        echo 
"Uploaded file type is: ".$ftype."<br>";
        echo 
"<hr>";
        
        
//save the uploaded file to the respective folder
        
$success=move_uploaded_file($tmpname,'newtext.txt');
        
        if(
$success){
            echo 
"File has been copied successfully<br>";
            echo 
"New file path and directory name is below: <br>";
            echo 
realpath('newtext.txt')."<p>";
            
        
//delete this uploaded file
        
unlink($tmpname);
        }else{
        
            echo 
"<font color='red'>Can not copy this file !</font>";
        }
    
    }
I can't see what would be causing no output (as script looks okay) unless it's a fatal error.

Hope that helps some.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Sep 18th, 2007, 20:28
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: weird uploading file

Quote:
Originally Posted by Rakuli View Post
Can you check your error log to see if there is any PHP error occurring.

Also a few hints

It is is much more secure to use is_uploaded_file() and move_uploaded_file() in PHP.

So you could change your code to be

PHP: Select all

<?php
//receiving uploaded file from client side
echo $_POST['uname']. " Hello:<p>";
$error_msg=$_FILES['ufile']['error'];
$fname=$_FILES['ufile']['name'];
$tmpname=$_FILES[['ufile']['tmp_name'];
$fsize=$_FILES['ufile']['size'];
$ftype=$_FILES['ufile']['type'];

//if to determining file be successfully uploaded
// Is uploaded file makes sure that the file was uploaded and not a user trying to use HTTP tricks to work with files it shouldn't
    
if(!is_uploaded_file($fname)){
        echo 
"<font color='red'> File has not been uploaded successfully!</font><p>";
        if (
$error_msg)
        echo 
"The relevanted error is: ".$error_msg;
    }else{
        
//file uploaded successfully
        
echo "Already received uploaded file, file name is: ".$fname."<br>";
        echo 
"File name is the server position as temp is: ".$tmpname."<br>";
        echo 
"Uploaded file size is: ".$fsize."<br>";
        echo 
"Uploaded file type is: ".$ftype."<br>";
        echo 
"<hr>";
        
        
//save the uploaded file to the respective folder
        
$success=move_uploaded_file($tmpname,'newtext.txt');
        
        if(
$success){
            echo 
"File has been copied successfully<br>";
            echo 
"New file path and directory name is below: <br>";
            echo 
realpath('newtext.txt')."<p>";
            
        
//delete this uploaded file
        
unlink($tmpname);
        }else{
        
            echo 
"<font color='red'>Can not copy this file !</font>";
        }
    
    }
I can't see what would be causing no output (as script looks okay) unless it's a fatal error.

Hope that helps some.
Thanks alot. Looks like got the same result, same issue. Browser didn't tell me any error.
Reply With Quote
  #4 (permalink)  
Old Sep 19th, 2007, 04:38
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: weird uploading file

Anything in your php error log?
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Sep 19th, 2007, 21:05
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: weird uploading file

Quote:
Originally Posted by Rakuli View Post
Anything in your php error log?
Thanks so much. There is the problem of duplicated '['

$tmpname=$_FILES[['ufile']['tmp_name'];
Reply With Quote
  #6 (permalink)  
Old Sep 20th, 2007, 05:05
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: weird uploading file

LOL I missed tha too from your code.

Error log is very helpful tool.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Support for File Uploading Sporky PHP Forum 2 Apr 19th, 2007 21:09
progress bar file uploading in vb.bet imranyf Introduce Yourself 4 Nov 9th, 2006 15:57
Weird IE bug? spinal007 Web Page Design 15 Sep 7th, 2006 14:17
Uploading visitors file to my site pokerskatershark Web Page Design 8 Jan 17th, 2006 01:22
Uploading file G-Shock Classic ASP 6 Dec 29th, 2005 05:18


All times are GMT. The time now is 05:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43