Jump to content

[SOLVED] Can you please help me in uploading files from client browse


Recommended Posts

Dear People,

 

Can you please help me in uploading files from client browse and storing in a specific folder?

 

I got this code, but it is not working. I believe it could be the placement.

 

 

<form action="examplefileupload.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" />

<?php

if (($_FILES["file"]["type"] == "image/gif")

|| ($_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

      {

      move_uploaded_file($_FILES["file"]["tmp_name"],

      "upload/" . $_FILES["file"]["name"]);

      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

      }

    }

  }

else

  {

  echo "Invalid file";

  }

?>

 

</form>

 

 

Dear People,

 

I redo my code, but no luck, I know it should work, but I think somthing is missing, please help

 

"

<form action="examplefileupload.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" />

<?php

if (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpg")&& ($_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

{

      move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);

      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

}

    }

}

else

{

  echo "ONLY Gif or JPG Files!";

}

?>

 

"

Let's look at an obvious setting situation. Have you checked your php settings to allow an upload to the directory you are trying to upload to? I had my code right and it took me a day and a half to figure out the directory was not set up to allow uploads.

 

Snowdog

1) Set the directory (to which the files will upload to) permissions to 777.

2) Replace your form to this:

<form action="examplefileupload.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>

(you didn't put the end tag for the form).

 

See if that helps.

Here is my upload code. This is the html form to choose your upload. In the first part I am passing variable some variables through so it knows what table and file I am uploading it and it changes the name of the file. Maybe this can help you. I pieced code together to come up with what worked for me. Hope this helps.

 

Snowdog

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>
 <head> 
   <title>Untitled</title>
 </head>
 <body>
 <?
 
   $id = $_REQUEST['id'];
   $filename = $_REQUEST['filename'].".mp3"; 
   echo "  <form enctype='multipart/form-data' method=\"post\" action=\"edit_reminder_upload_file.php\">\n";
   echo "  Upload file and rename it to $filename\n";
   echo "  <table width=\"90%\" align=\"center\">\n";
   echo "    <tr>\n";
   echo "      <td width=\"150\" style=\"font-family: verdana; font-size: 12;\">New File:</td>\n";
   echo "      <td style=\"font-family: verdana; font-size: 12;\"><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"500000000\" /><input type=\"file\" name=\"thumb\" value=\"\"></td>\n";
   echo "    </tr>\n";
   echo "  </table>";
   echo "        <input type=\"hidden\" name=\"filename\" value=\"$filename\">\n";
   echo "        <input type=\"hidden\" name=\"id\" value=\"$id\">\n";
   echo "        <input type=\"submit\" name=\"submit\" value=\"submit changes\">\n";
   echo "  </form>";
 ?>
 </body>
</html>

 

and here is the 2nd part of upload where it does the work.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

 <head> 
   <title>Untitled</title>
 </head>

 <body>

<?
$filename = $_REQUEST['filename']; 
$id = $_REQUEST['id']; 

if(move_uploaded_file($_FILES['thumb']['tmp_name'], "mp3/coaching_call/".$filename))
{
 echo "Upload Success"; 
 include("include/config.php");
 $query = "UPDATE call_reminder SET completed='1' WHERE id='$id'"; 
 mysql_query($query) or die('Query failed: ' . mysql_error());
}
else
{
 echo "Upload Failed";  
}
?>

 </body>
</html>

Thanks friends,

 

I manged to get my code working but with the following error, can you please help me understand the error

 

"

 

Warning: move_uploaded_file(upload/image.GIF) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\MyPHP\examplefileupload.php on line 71

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php3F.tmp' to 'upload/image.GIF' in C:\wamp\www\MyPHP\examplefileupload.php on line 71

Stored in: upload/image.GIF

 

"

 

Line 71 is "move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);"

 

SnowDog, I have not tried your code yet.

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.