|
-
Apr 17th, 2004, 11:29 AM
#1
Upload files with PHP [Resolved*3]
And here we go again. More or less just me asking questions here now...
I found an example in my Beginning PHP4 book from wrox on how to upload files to the server. But the explenation is a bit hard to understand. Here is the code
PHP Code:
<?
//file_upload.php
$archive_dir = "./bildebox";
function upload_form() {
global $PHP_SELF;
?>
<FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA"
ACTION="<? echo $PHP_SELF ?>">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="upload">
Upload file!
<INPUT TYPE="FILE" NAME="userfile">
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="upload">
</FORM>
<?
}
function upload_file() {
global $userfile, $userfile_name, $userfile_size,
$userfile_type, $archive_dir, $WINDIR;
if(isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile);
$filename = basename($userfile_name);
if($userfile_size <= 0) die ("$filename is empty.");
if(!@copy($userfile, "$archive_dir/$filename"))
die("Can't copy $userfile_name to $filename.");
if(!isset($WINDIR) && !@unlink($userfile))
die ("Can't delete the file $userfile_name.");
echo "$filename has been successfully uploaded.<BR>";
echo "Filesize: " . number_format($userfile_size) . "<BR>";
echo "Filetype: $userfile_type<BR>";
}
?>
<HTML>
<HEAD><TITLE>FILE UPLOAD</TITLE></HEAD>
<BODY>
<?
if($action == 'upload') upload_file();
else upload_form();
?>
</BODY>
</HTML>
In my "public_html" folder, I have a folder called "klubbny", in that folder I have two folders. One called "oppdater" where I have this page, and one called bildebox, where I want to upload the file to.
What am I doing wrong here. I am getting the message:
Can't copy f.gif to f.gif.
Am my link in the top:
$archive_dir = "./bildebox";
wrong...should I write the whole path, or what. Not getting the path system here completly.
Thanks ØØ
Last edited by NoteMe; Apr 18th, 2004 at 02:09 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|