webForumDet fria alternativet

Hjälp med copy() kod !!

PHPur PHP

6 svar · 312 visningar · startad av liquid

liquidMedlem sedan feb. 20033 inlägg
#1

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!!!!

Nexus86Medlem sedan okt. 20023 030 inlägg
#2

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

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 ;))

liquidMedlem sedan feb. 20033 inlägg
#3

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

Nexus86Medlem sedan okt. 20023 030 inlägg
#4

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..!

rIkLuNdMedlem sedan feb. 2003169 inlägg
#5
<?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!!"; 
} 
} 

?>
liquidMedlem sedan feb. 20033 inlägg
#6

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

rIkLuNdMedlem sedan feb. 2003169 inlägg
#7

Vassego! :birp

144 ms totalt · 3 externa anrop · v20260731065814-full.29ac60f6
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
141 ms — hämta tråd, inlägg och bilagor (db)