Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Upload file problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Upload file problem

Postby ylkien » Fri Jan 31, 2003 6:55 am

Hi there,
i have read in the forums that i need to enable uploading for the webserver. Does that include for apache 2? I went through the config for it, & i can't find any upload thing for apache.

I have enable upload in php to this folder "e:/upload". But, it is unable to upload the file. No error was displayed, only the message "Couldn't copy the file" which is in the code. This is the html code, followed by the php code.

<html>
<head>
<title>Upload a file</title>
</head>
<body>
<h1>Upload a File</h1>

<form method = "post" Action = "do_upload.php" enctype = "multipart/form-data">

<P><strong>File to be Upload : </strong><br>
<input type = "file" Name = "img1" size="50"></p>

<p><input type = "submit" Name = "submit" value="upload file"></p>

</form>
</body>
</html>


<?

if ($img1_name != "") {
@copy("img1", "e:/upload/$img1_name") or die("Couldn't copy the file");

} else {
die("No input file specified");
}
?>

<html>
<head>
<title>Successful File Upload</title>
</head>
<body>
<h1>Success!</h1>
<P>You send :<? echo "$img1_name"; ?>, a <? echo "img1_size"; ?> byte file with a mime type of <? echo "$img1_type"; ?> </p>

</body>
</html>
ylkien
New php-forum User
New php-forum User
 
Posts: 28
Joined: Sat Dec 14, 2002 9:43 am

Postby Joan Garnet » Sat Feb 01, 2003 2:21 pm

Try this one:
Code: Select all
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
Send files:<br>
<input type="submit" value="Transfer">
</form>

<?php
if ($HTTP_POST_VARS){
   $dir = "my_dir":
   $filename = $_FILES['userfile']['name'];
   if ( !@copy ( $_FILES['userfile']['tmp_name'] , $dir."/".$filename) ){
      echo "<b>".$file." </b>couldn't be copied !!<b><br>";
   }else{
      echo "<b>".$file."</b> has been succesfully copied!<br>";
   }
}

?>

And be sure that permissions for that folder are set for upload.
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron