0

The html file

<html>
<head><title> Form Uploading </title></head>
<body>
<h3>File upload </h3>
Select a File <BR />
<Form action ="upload.php" method = "post" enctype="multipart/form-data">
<input type="file" name ="file" sieze = "50" >
<input type ="submit" value = "Upload File">
</form>
<body>
</html>

The php file

<?php
if($_FILES[ 'file'][ 'name' ] != ""){
       copy ( $_FILES[ 'file'][ 'name' ], "C:\Users\Acasa\Desktop".$_FILES[ 'file'][ 'name' ]) ;#or 
       #die( "Could not copy file!");
    echo $_FILES[ 'file'][ 'name' ];
}else{ 


echo "Sent File".$_FILES[ 'file' ][ 'name']."<BR />";
echo "Size File".$_FILES[ 'file' ][ 'size']."<BR />";
echo "Type File".$_FILES[ 'file' ][ 'type']."<BR />";
}
?>

Both are in the same dir.

I want to try the code from tutorialspoint.com but for some reason it`s not working... I want to copy the uploaded file into another dir they used function copy and not move_uploaded_file

Any suggestion why it`s not working?

9
  • 2
    Don't use that tutorial. It is obsolete and insecure. Commented Dec 7, 2013 at 15:50
  • Whenever something doesn't work, enable error_reporting. It'll give you two hints here. Commented Dec 7, 2013 at 15:52
  • 1
    Use move_uploaded_file with $_FILES['file']['tmp_name'] instead of copy. Commented Dec 7, 2013 at 15:52
  • Yea it have some good parts and some bad parts...Any php site tutorial you know? Thanks in advance Commented Dec 7, 2013 at 15:53
  • 1
    I want to copy the uploaded file into another dir they used function copy and not move_uploaded_file so you want to do this the wrong way on purpose? Is this how you aim to learn PHP? Do you think this is a desirable skill for a programmer to have? Commented Dec 7, 2013 at 15:55

3 Answers 3

2

You should use the move_uploaded_file() function instead of copy() :

<?php
if ( move_uploaded_file ( $_FILES["file"]["tmp_name"] , 
     "YOUR_PATH".$your_file_name ) )
   echo "Download completed";
else
   echo "Error";
?>

Don't forget to check format, size, etc.. before.

Sign up to request clarification or add additional context in comments.

Comments

0
<?php
if($_FILES[ 'file'][ 'name' ] != ""){
       move_uploaded_file ( $_FILES[ 'file'][ 'tmp_name' ], "C:\Users\Acasa\Desktop".$_FILES[ 'file'][ 'name' ]) or 
       die( "Could not copy file!");
}else{ 
    die("no file found");
}

echo "Sent File: ".$_FILES[ 'file' ][ 'name']."<BR />";
echo "Size File: ".$_FILES[ 'file' ][ 'size']."<BR />";
echo "Type File: ".$_FILES[ 'file' ][ 'type']."<BR />";

?>

Comments

0

It is working. You should use the move_uploaded_file() function instead of copy() :

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.