Google Answers Logo
View Question
 
Q: How to use PHP to make upload/download feature ( No Answer,   1 Comment )
Question  
Subject: How to use PHP to make upload/download feature
Category: Computers > Internet
Asked by: xanaboy-ga
List Price: $9.00
Posted: 11 Jun 2006 14:11 PDT
Expires: 11 Jul 2006 14:11 PDT
Question ID: 737268
hello dear experts.

I have a paid space (Bronze plan at this page for features
http://www.canaca.com/virtual.html)

And I really want to add a file upload/download feature,
just to store some files when I see them. 

---something like this (http://www.yousendit.com/)


But I would like all the files I upload goes into 1 folder, 
so I can keep track of them.


well if u have any question pls ask,

thanks
Answer  
There is no answer at this time.

Comments  
Subject: Re: How to use PHP to make upload/download feature
From: srirangan-ga on 14 Jun 2006 22:39 PDT
 
Hello xanaboy-ga,

I'm not able to post an "answer" but I can post a comment.

I have written an article about handling file uploads, its a very
simple two-step article. I think it will help you, you may view it at:
http://programmerassist.com/article/320

I will also post it here for your assistance.

Handling File Uploads With PHP
article by Srirangan

This is a minimalistic guide on how to handle file uploads using PHP
and XHTML forms. Prerequisites are basic XHTML and PHP skills.

== Step 1: Creating an XHTML form ==

A form needs to be created through which a user can select the file
that needs to be uploaded and pass it on to the PHP script which
uploads the file. It's a very simple form using the "input type=file"
attribute.

<form enctype="multipart/form-data" action="__URL__" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>

== Step 2: Processing the upload ==

Now comes the PHP part. The approach I use here is to make use of the
move_uploaded_file() and the global $_FILES variable.


<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.
";
} else {
echo "Possible file upload attack!
";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

== Notes ==

- Provide your file with sufficient permissions, should that the
requisite write permissions in your operating system

- Modify the $uploaddir variable suitably to point to the writable
folder where you want to save the uploaded files

== References ==

[1] PHP Documentation

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy