Attachments

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jay87
Forum Commoner
Posts: 61
Joined: Thu Jan 07, 2010 5:22 am

Attachments

Post by Jay87 »

I have the following code for adding attachments:

Code: Select all

[color=#FF0000]<?php[/color]
$uploaddir = date("F")." '".date("y");
[color=#0000FF]if[/color] ($_FILES["file"]["size"] < [color=#FF8000]2000000[/color])
  [color=#800080]{[/color]
  [color=#0000FF]if[/color] ($_FILES["file"]["error"] > [color=#FF8000]0[/color])
    [color=#800080]{[/color]
    [color=#0000FF]echo[/color] "Return Code: " . $_FILES["file"]["error"] . "<br />";
    [color=#800080]}[/color]
  [color=#0000FF]else[/color]
    [color=#800080]{[/color]
    [color=#0000FF]echo[/color] "Upload: " . $_FILES["file"]["name"] . "<br />";
    [color=#0000FF]echo[/color] "Type: " . $_FILES["file"]["type"] . "<br />";
    [color=#0000FF]echo[/color] "Size: " . ($_FILES["file"]["size"] / [color=#FF8000]1024[/color]) . " Kb<br />";
    [color=#0000FF]echo[/color] "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
 
    [color=#0000FF]if[/color] (file_exists("upload/" . $uploaddir."/". $_FILES["file"]["name"]))
      [color=#800080]{[/color]
      [color=#0000FF]echo[/color] $_FILES["file"]["name"] . " already exists. ";
      [color=#800080]}[/color]
    [color=#0000FF]else[/color]
      [color=#800080]{[/color] mkdir("uploads/" . $uploaddir);
      move_uploaded_file($_FILES["file"]["tmp_name"], "\\192.168.1.202\web\helpdesk-dev\upload/" . $uploaddir."/". $_FILES["file"]["name"]);
      [color=#0000FF]echo[/color] "Stored in: " . "upload/" . $uploaddir."/". $_FILES["file"]["name"];
      [color=#800080]}[/color]
    [color=#800080]}[/color]
  [color=#800080]}[/color]
else
  [color=#800080]{[/color]
  echo "Invalid file";
  [color=#800080]}[/color]
[color=#FF0000]?>[/color]
and

Code: Select all

        <table width=800 height=50% class='smooth'>
 
        <tr><td class=smooth height=10%>Attachement(s)</td></tr>
        <tr><td><?echo $_FILES["file"]["name"] ?></td></tr>
        </table>
        
        
        <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>
When trying to attach the file, it all goes through fine and no errors pop up but the file i try and attach never shows up anywhere...

Any ideas?


:banghead:
rmrbest
Forum Newbie
Posts: 8
Joined: Fri Feb 26, 2010 2:32 am

Re: Attachments

Post by rmrbest »

Please, file is moved to target? and the problem was <tr><td><?echo $_FILES["file"]["name"] ?></td></tr> not appear name file??

Thanks,

Raul.
Jay87
Forum Commoner
Posts: 61
Joined: Thu Jan 07, 2010 5:22 am

Re: Attachments

Post by Jay87 »

the problem is that the file doesn't seem to upload anywhere, can't even find the temp file before it is supposed to move to the upload folder?!
rmrbest
Forum Newbie
Posts: 8
Joined: Fri Feb 26, 2010 2:32 am

Re: Attachments

Post by rmrbest »

First, the operating system is Windows? Note that you must put double \. On the other hand, you have permissions to the folder or directory you create?
Post Reply