Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-14-2011, 07:37 PM php upload
Junior Talker

Posts: 3
Trades: 0
Hi, I am having troubles uploading files with PHP.

Form
HTML Code:
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>
Handler Page
PHP Code:
<?php
if ($_FILES["file"]["error"] > 0)
{
echo 
"Error: " $_FILES["file"]["error"] . "<br />";
}
else
{
echo 
"Upload: " $_FILES["file"]["name"] . "<br />";
echo 
"Type: " $_FILES["file"]["type"] . "<br />";
echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo 
"Stored in: " $_FILES["file"]["tmp_name"];
}
?>
I can browse-to and upload the file, but I get the following output when I click submit:

Code:
0) {echo "Error: " . $_FILES["file"]["error"] ."
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . " 
echo "Type: " . $_FILES["file"]["type"] . "
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb ";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}

I am new. Do I need to create a folder so attached files can be saved?

Thanks.

Last edited by Physicsguy; 08-14-2011 at 08:35 PM..
bangla123 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-14-2011, 08:36 PM Re: php upload
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
The script is outputting exactly what you've told it to. You're telling it to first check for errors, and if there are any, display them. If there aren't, how the file's information. The output you've given is what the script is told to do.

What exactly are you trying to accomplish?
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-14-2011, 09:04 PM Re: php upload
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP is not enabled
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-15-2011, 10:40 AM Re: php upload
Junior Talker

Posts: 3
Trades: 0
Hi,

I am simply trying to upload a file and save the uploaded file in server. so i can view it later.

i spent long time still failed.
Thanks.
bangla123 is offline
Reply With Quote
View Public Profile
 
Old 08-15-2011, 10:52 AM Re: php upload
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
As Keith already said, the server doesn't seem to have PHP enabled. The code is not being run at all, just sent to the browser. Either your server does not have PHP installed, or it is not working for some reason.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-15-2011, 12:33 PM Re: php upload
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Oooh, I thought he meant that code was outputting to the browser. Silly me .

What's happening is the PHP is being parsed as XML, using the <? and ?> tags (which is XML). PHP pages need to be saved as .php, as opposed to .html or .htm.

PHP needs to be installed (and enabled?) on your server. If this is a localhost running on a *nix-based PC, open the Synaptic and install yourself a LAMP server. If you're on Windows, install a WAMP (or get XAMPP) instead.

.html will work in all browsers, without any extra stuff, because browsers display HTML. No internet browser knows how to 'decode' or execute PHP, because that is server-side. You have to have a server to give the correct output to your browser
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-15-2011, 01:52 PM Re: php upload
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
PHP pages need to be saved as .php, as opposed to .html or .htm.
This really depends on your server config. You can use whatever extension you'd like so long as you setup the server to parse files with that extension. Many PHP sites use .html extensions.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-15-2011, 01:54 PM Re: php upload
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
That's true, even for Tycoon Talk. .htaccess's AddType helps with that, though, most likely.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-15-2011, 02:23 PM Re: php upload
Junior Talker

Posts: 3
Trades: 0
i am working in remote hosting server.
i am using FileZila to upload the file.
Hosting server is php configured. i would assume php is enabled.

Thanks.
bangla123 is offline
Reply With Quote
View Public Profile
 
Old 08-15-2011, 02:35 PM Re: php upload
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
There's one way to find out.

Create a file called 'phpinfo.php'. In it, put this code:

PHP Code:
<?php
phpinfo
();
?>
If something shows up, you're good.

FileZilla is an FTP client, which allows you to connect to your server and upload files. HTTP (Hypertext transfer protocol) displays HTML, and FTP (file transfer protocol) uploads them.
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php upload
 

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41404 seconds with 12 queries