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
Jay87
Forum Commoner
Posts: 61 Joined: Thu Jan 07, 2010 5:22 am
Post
by Jay87 » Mon Jan 25, 2010 3:37 am
I have the following code on the page i want the attachments to be...
The table works fine and allows me to 'chose a file' and submit it...
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>
This code is suppose to re-direct the upload into the folder 'upload' from 'temp_file' (i think?), but after i upload something it never appears in the upload folder. Any ideas on where i am going wrong?
Code: Select all
<?php
if ($_FILES["file"]["size"] < 2000000)
{
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";
}
?>
Also how can i show the files that have been attached on the page?
Jay87
Forum Commoner
Posts: 61 Joined: Thu Jan 07, 2010 5:22 am
Post
by Jay87 » Mon Jan 25, 2010 5:02 am
I've changed the code to the following:
Code: Select all
<?php
$uploaddir = date("F")." '".date("y");
if ($_FILES["file"]["size"] < 2000000)
{
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/" . $uploaddir."/". $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{ mkdir("uploads/" . $uploaddir);
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $uploaddir."/". $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $uploaddir."/". $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
I get the following errors:
- PHP Warning: move_uploaded_file(upload/January '10/helpdesk-original2.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in /var/www/helpdesk-dev/upload_file.php on line 22, referer:
http://helpdesk:90/viewcall.php?id=0094 ... 10&sub=att
-PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpuHaKEF' to 'upload/January '10/helpdesk-original2.jpg' in /var/www/helpdesk-dev/upload_file.php on line 22, referer:
http://helpdesk:90/viewcall.php?id=0094 ... 10&sub=att
whistler
Forum Newbie
Posts: 4 Joined: Mon Jan 25, 2010 5:07 am
Post
by whistler » Mon Jan 25, 2010 5:28 am
As sleep deprived as I am, this is somewhat hilarious that we're working on the same bit of code.
I'm fairly sure that you need to check the permissions on the folder that you're trying to save the uploaded files to.
Try that, and I'll reread the changes you've made to the code.
Jay87
Forum Commoner
Posts: 61 Joined: Thu Jan 07, 2010 5:22 am
Post
by Jay87 » Mon Jan 25, 2010 5:52 am
whistler wrote: As sleep deprived as I am, this is somewhat hilarious that we're working on the same bit of code.
I'm fairly sure that you need to check the permissions on the folder that you're trying to save the uploaded files to.
Try that, and I'll reread the changes you've made to the code.
Everything is ticked on the 'upload' folder, so it should allow for new files to be copied into it...!