[SOLVED] move_uploaded_file problems...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

dogdaynoon
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Mar 14, 2011 9:48 pm

[SOLVED] move_uploaded_file problems...

Postby dogdaynoon » Tue Oct 16, 2012 9:34 pm

Here is my code. Very simple....
html like this:

Code: Select all

<html>
<head>
<title>test php</title>
</head>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
        <input type="file" name="file" id="file" />
        <br />
        <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>


php like this:

Code: Select all

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

  $filename = $_FILES["file"]["tmp_name"];
  $destination = "C:\\TMP";
  move_uploaded_file($filename, $destination);
 
  echo "<br />" . $filename . "<br /><hr />" . $destination;
?>


You guessed it error messages like this:

Warning: move_uploaded_file(C:\TMP1) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Program Files\Apache Software Foundation\Apache2.2\sites\test\upload_file.php on line 7

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\TMP\php9E5.tmp' to 'C:\TMP1' in C:\Program Files\Apache Software Foundation\Apache2.2\sites\test\upload_file.php on line 7

C:\TMP\php9E5.tmp
C:\TMP1


information:
windows xp pro srv pack 3
apache 2.2
php 5.2.17
mysql ?

So my C:TMP file has full permissions for EVERYONE. I did this because i just want it to be known
that it is wide open. There shouldn't be any permission issues.
Do i need to do something in Apache http.conf file?
for the record php.ini has
safe_mode off
file_upload on
upload_max_filesize = 10000M
post_max_size = 10000M
I have restarted apache after checking these configs.

Why isn't it working?
Last edited by dogdaynoon on Wed Oct 17, 2012 7:53 am, edited 1 time in total.

dogdaynoon
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Mar 14, 2011 9:48 pm

Re: move_uploaded_file problems...

Postby dogdaynoon » Wed Oct 17, 2012 7:53 am

Solved this problem:
the error was coming from not setting the destination path correctly.
I had the following:

Code: Select all

$filename = $_FILES["file"]["tmp_name"];
  $destination = "C:\\TMP";
  move_uploaded_file($filename, $destination);


when what is really needed is a filename along with the destination path.
Like this:

Code: Select all

$filename = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
$destination = "C:\\TMP" . $name;
move_uploaded_file($filename, $destination);


Well there went 3 days.
Good luck to anyone else having this problem.

dogdaynoon

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: [SOLVED] move_uploaded_file problems...

Postby seandisanti » Thu Oct 18, 2012 7:18 am

Cool, thanks for posting the solution too.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest