---
title: "Hjälp med copy() kod !!"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/68491-hjälp-med-copy-kod"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "liquid"
published: "2003-02-16T23:16:06.000Z"
updated: "2003-02-17T00:04:27.000Z"
replies: 6
views: 321
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/68491-hjälp-med-copy-kod"
---

# Hjälp med copy() kod !!

## #1 — liquid, 2003-02-16T23:16Z

Nu jag säkert stans största n00b innom php.
men jag försöker göra så att man lätt ska kunna ladda upp en fil till en katalog i windows... har gjort 2 php filer

fil 1:

\<?php
//User_Upload.php

	include "User_Upload_Functions.php";

  $upload_success ='';

// RUNS THE UPLOAD FUNCTION
User_Upload_Function();

// SHOWS THE UPLOAD FORM
User_Upload_Form();

 global $upload_success;
 echo $upload_success;

?\>

och fil 2:

\<?php
//User_Upload_Functions.php

// RUNS THE UPLOAD FUNCTION
function User_Upload_Function()
{
	global $upload_success;
	
       
       if (isset($\_POST\["upload"\]))
       {
	        copy($\_POST\["file"\], "C:\\Inetpub\\wwwroot\\php\\jolle\\upload\\$\_POST\['file'\]") or die ("Couldn´t copy");
	        $upload_success = "Uppladdningen lyckades!!";
       }
}

// SHOWS THE UPLOAD FORM
function User_Upload_Form()
{		
	
	
echo "\<form action='" . $\_SERVER\['PHP_SELF'\] . "' method='post' enctype='multipart/form-data'\>";
echo "\<input type='file' name='file'\>\<br/\>";
echo "\<input type='submit' name='upload' value='Upload file'\>";
echo "\</form\>";
}

?\>

Jag får bara felmedelande :

Notice: Undefined index: file in c:\\inetpub\\wwwroot\\php\\jolle\\User_Upload_Functions.php on line 14

Warning: Unable to open '' for reading: Permission denied in c:\\inetpub\\wwwroot\\php\\jolle\\User_Upload_Functions.php on line 14
Couldn´t copy

Hjälp please!!!!

Permalänk: https://www.webforum.nu/p/68491

## #2 — Nexus86, 2003-02-16T23:23Z

> copy($\_POST\["file"\], "C:\\Inetpub\\wwwroot\\php\\jolle\\upload\\$\_POST\['file'\]") or die ("Couldn´t copy");

```php
copy($_POST["file"], "C:\\\\Inetpub\\\\wwwroot\\\\php\\\\jolle\\\\upload\\\\$_POST['file']") or die("Couldn´t copy");
```

\*host host\* Om jag minns rätt så ska det i alla fall vara två backslash.. Vet inte om det är det som är felet men kanske.. :)

EDIT // btw Välkommen till wF. :bire (eller i alla fall ditt första inlägg ;))

Permalänk: https://www.webforum.nu/p/952486

## #3 — liquid, 2003-02-16T23:34Z

Nope får bara felmeddelandet:

Notice: Undefined index: files in c:\\inetpub\\wwwroot\\php\\jolle\\User_Upload_Functions.php on line 17

Warning: Unable to open '' for reading: Permission denied in c:\\inetpub\\wwwroot\\php\\jolle\\User_Upload_Functions.php on line 17
Couldn´t copy

dett kan ta lång tid... bleh

Permalänk: https://www.webforum.nu/p/952491

## #4 — Nexus86, 2003-02-16T23:41Z

> **användarkommentar på php.net skrev:**
>
> // The easiest way to upload/copy a file to the server
> 
> \<HTML\>
> \<TITLE\>
> File upload
> \</title\>
> \<body\>
> 
> \<B\>File upload\</b\>
> 
> 
> 
> \<form enctype="multipart/form-data" action="\<?PHP echo $PHP_SELF ?\>" method="post"\>
> 
> \<!-- "MAX_FILE_SIZE" determines the biggest size an uploaded file can occupy --\>
> 
> \<input type="hidden" name="MAX_FILE_SIZE" value="500000"\>
> Send this file: 
>  \<input name="userfile" type="file"\>
> \<input type="submit" name="submit" value="Send File"\>
> \</form\>
> 
> \</body\>
> 
> \<?PHP
> 
> /\* 
> 
> $userfile - The temporary filename in which the uploaded file was stored on the server machine. 
> 
> $userfile_name - The original name or path of the file on the sender's system. 
> 
> $userfile_size - The size of the uploaded file in bytes. 
> 
> $userfile_type - The mime type of the file if the browser provided this information. An example would be "image/gif". 
>  
> \*/
> 
> // copy to this directory
> 
> $dir="./bor/";
> 
>  
> // copy the file to the server
> 
> if (isset($submit)){
> 
> copy($userfile,$dir.$userfile_name); 
> 
> if (!is_uploaded_file ($userfile)){
> 
> echo "
> \<b\>$userfile_name\</b\> couldn't be copied !!";
> }
> }
> 
> // check whether it has been uploaded
> 
> if (is_uploaded_file ($userfile)){
> 
> echo "
> \<b\>$userfile_name\</b\> copied succesfully !!";
> 
> }
> 
> ?\>
> 
> \</html\>

Hinner inte läsa igenom. Ska upp tidigt imorgon. Men hoppas du hittar vad du söker..!

Permalänk: https://www.webforum.nu/p/952498

## #5 — rIkLuNd, 2003-02-16T23:45Z

```php
<?php

function User_Upload_Function() 
{ 
global $upload_success; 

if (isset($_POST['upload'])) 
{ 
copy($_FILES['file']['tmp_name'], "C:\Inetpub\wwwroot\php\jolle\upload\".$_FILES['file']['name']) or die ("Couldn´t copy"); 
$upload_success = "Uppladdningen lyckades!!"; 
} 
} 

?>
```

Permalänk: https://www.webforum.nu/p/952500

## #6 — liquid, 2003-02-17T00:03Z

tack för hjälpen.... nu funkar det..... är skyldiga er en öl!!!!!!

Permalänk: https://www.webforum.nu/p/952504

## #7 — rIkLuNd, 2003-02-17T00:04Z

Vassego!  :birp

Permalänk: https://www.webforum.nu/p/952506

---

Tråden på webben: https://www.webforum.nu/amne/php/68491-hjälp-med-copy-kod
