SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: uploading a picture
-
Sep 11, 2001, 06:11 #1
- Join Date
- Sep 2001
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
uploading a picture
how can i upload a picture using php and store it in a specific folder ?!
and how can i call it ?!
thank youONLY LaZiO and ArGaNTiNa ...
-
Sep 11, 2001, 06:54 #2
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The manual has a very good chapter that explain how:
http://www.php.net/manual/en/features.file-upload.php
-
Sep 12, 2001, 00:44 #3
- Join Date
- Jun 2001
- Location
- Dublin
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I found the following recently on Zend. I had to change it for my own purposes but may give you a head start.
All original comments are intact
PHP Code:<?
/********************************************************************
* file uploader - file uploader code snippet.
* maxsize :
* - you can set the maxsixe, if file size exceed maxsize it won't proceed;
* - you can set the quota, if dir size exceed quota it won't proceed;
* - you can set the ext, if file name extension listed on this array it won't proceed;
*
* Copyright (C) 2001 Wibisono Sastrodiwiryo.
* This program is free software licensed under the
* GNU General Public License (GPL).
*
* CyberGL => Application Service Provider
* [url]http://www.cybergl.co.id[/url]
* [email]office@cybergl.co.id[/email]
*
* $Id: uploader2.php3,v 0.2 2001/07/23 22:3:34 wibi Exp $
*********************************************************************/
$dir ="/www/servers/upload"; # your uploaded file dir, this dir require proper permission to write access
$temp ="/tmp"; # unix system temp dir
$maxsize ="40960"; # max 40 Kb
$quota = 524288; # define space quota 500 Kb
$ext = array(".p", ".php", ".php3", ".phtml", ".shtml"); # define file extension to reject
if ($userfile AND $userfile != "none") {
$total=0;
$handle=opendir($dir);
while ($file = readdir($handle)) {
if (is_file("$dir/$file")) {$total+=filesize("$dir/$file");}
}
while (list($key,$val) = each($ext)) {
if (strstr($userfile_name, $val)) {$invalidext=true;break;}
}
if ($userfile_size > $maxsize) {echo "ERR: File too large";}
elseif ($invalidext) {echo "ERR: Forbiden file extension";}
elseif ($total > $quota) {echo "ERR: Space quota exceeded";}
else {
rename("$userfile", "$temp/$userfile_name");
copy("$temp/$userfile_name", "$dir/$userfile_name");
unlink("$temp/$userfile_name");
echo "OK: File \"$userfile_name\" uploaded succesfully";
}
} else {
?>
<form action="<?echo $PHP_SELF?>" method=POST ENCTYPE="multipart/form-data">
<table>
<tr>
<td class=navbox>Select File:</td>
<td>:</td>
<td><input type=file name=userfile></td>
</tr>
<tr>
<td class=navbox> </td>
<td> </td>
<td><input type=submit value=Upload></td>
</tr>
</table>
</form>
<?}?>
-
Sep 12, 2001, 04:52 #4
- Join Date
- Sep 2001
- Posts
- 31
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks so much lveale
and you too freakysid
Iveale, your code helped me alot to finish my problem
freakysid, the php manual sometime makes you very confused.ONLY LaZiO and ArGaNTiNa ...
Bookmarks