Jump to content

Uploading Files


narjis

Recommended Posts

I am using xammp with FileZilla running on it. I've changed my php.ini  settings

to "C:/xxx/tmp" directory but am unable to upload a file. Th cod is  running but

it dos not seem to upload the temporary fil. Plase somebody help  me. ALso my form in upload.html  has <form action="upload_file.php" method="post" enctype="multipart/form-data">

Link to comment
Share on other sites

 

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


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      if(is_uploaded_file($_FILES["file"]["name"]))  {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  

Link to comment
Share on other sites

whn I run with print_r command thn it shows the following path but I cannot view th php2C.tmp file in the folder. Also move_uploaded_file() command also gives the same warning as unable to open file stream no such file exists. Please help

 

 

Array

(

    [file] => Array

        (

            [name] => w6.jpg

            [type] => image/jpeg

            [tmp_name] => C:\xxx\anonymous\php2C.tmp

            [error] => 0

            => 8268

        )

 

)

 

Link to comment
Share on other sites

This line:

if(is_uploaded_file($_FILES["file"]["name"]))  {

For proper working' date=' the function is_uploaded_file() needs an argument like $_FILES['userfile'']['tmp_name'], - the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work.

 

Should probably be:

if(is_uploaded_file($_FILES["file"]["tmp_name"]))  {

 

Or,

if(move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"])) {
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }

Link to comment
Share on other sites

Only the following errers

Warning: move_uploaded_file(upload/w5.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xxxx\xxxx\samples\Upload_file.php on line 37

and

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\anonymous\php69.tmp' to 'upload/w6.jpg' in C:\xampp\xxx\samples\Upload_file.php on line 26

each time it gives a random nam.tmp

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.