Jump to content

Archived

This topic is now archived and is closed to further replies.

Heero

PHP - Move_Uploaded File Error

Recommended Posts

Hello all,

I am running this code on my [url=http://202.71.227.137/rehab/CMS/cmsadmin/move_uploaded_file.php]server[/url]:

[CODE]
<?php
include("phpincludes/userSessionCheck.php");

if (!isset($_REQUEST["seenform"])) {
?>
  <form enctype="multipart/form-data" action="move_uploaded_file.php" method="post">
  Upload file: <input name="userfile" type="file">
  <input type="submit" value="Upload">
  <input type="hidden" name="seenform">
  </form>
<?php
} else {
  $uploaded_dir = "/upload/";
  $filename = $_FILES["userfile"]["name"];
  $path = $uploaded_dir . $filename;

  print "Temporary name: " . $_FILES['userfile']['tmp_name'] . "<br>";
  print "Original name: $filename<br>";
  print "Destination: $path<br>";

  if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $path)) {
      print "Uploaded file moved";
      // do something with the file here
  } else {
      print "Move failed";
  }
}

?>
[/CODE]

But I keep getting an move error. 

[QUOTE]
Temporary name: /tmp/phpx6PnbE
Original name: book_32.psd
Destination: /upload/book_32.psd
Move failed
[/QUOTE]

What can possible be creating this problem?

Share this post


Link to post
Share on other sites
do u have the folder that u want to move it too set to 777
if not u need to CHMOD that folder to 777

Share this post


Link to post
Share on other sites
COol that fixed the problem.  But isn't it dangerous to set it to complete modification for the folder (ie. 777)?

Share this post


Link to post
Share on other sites
um somtimes but not if your just setting it to one folder that doesnt have anything in it

Share this post


Link to post
Share on other sites
Oh okay...just curious...why would I even set a folder to full permissions if I won't anything in it?

Share this post


Link to post
Share on other sites
thats why uploads should always go in thier own folder(or series of folders) and NEVER in ur main directory!

Share this post


Link to post
Share on other sites

be also carefull the correct form format is as follows.

notice the upper case letters and words .


<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.