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
<?erick?>
Forum Newbie
Posts: 12 Joined: Thu May 29, 2008 8:36 am
Post
by <?erick?> » Wed Jun 18, 2008 4:43 am
what's wrong in my code? bec. when i trying to add attachment it is always failed. i cant add to database also the path directory..
Code: Select all
<?
if(isset($_POST['upload']))
{
$file['file']=$_FILES['file']['tmp_name'];
$file['size']=$_FILES['file']['size'];
$ext='';
$file['extent'] = pathinfo(strtolower($_FILES['file']['name']));
$file['name']=(isset($file['extent']['extension'])) ? strtolower($user.".".$file['extent']['extension']) : '';
$uploadDir = 'my directory';
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$file['name']);
}
}
//db
$query = "INSERT INTO upload (name, size, type, path) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed :' . mysql_error());
?>
<form action="" method="post">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="file" type="file" class="box" id="file">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
</tr>
</table>
</form>
WebbieDave
Forum Contributor
Posts: 213 Joined: Sun Jul 15, 2007 7:07 am
Post
by WebbieDave » Wed Jun 18, 2008 6:08 am
What errors/warnings are you receiving? Place the following at the top of your script:
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
That should shed some light on what's wrong in your code.
ragnis12
Forum Newbie
Posts: 12 Joined: Tue Jun 17, 2008 4:14 am
Post
by ragnis12 » Wed Jun 18, 2008 6:11 am
Code: Select all
<?php
if(isset($_POST['upload']))
{
$file = array();
$file['file'] = $_FILES['file']['tmp_name'];
$file['size'] = $_FILES['file']['size'];
$ext = '';
$file['extent'] = pathinfo(strtolower($_FILES['file']['name']));
$file['name'] = (isset($file['extent']['extension'])) ? strtolower($user.".".$file['extent']['extension']) : '';
$uploadDir = 'my directory';
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$file['name']);
}
}
//db
$query = "INSERT INTO upload (name, size, type, path) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed :' . mysql_error());
?>
<form action="" method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="file" type="file" class="box" id="file">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
</tr>
</table>
</form>
<?erick?>
Forum Newbie
Posts: 12 Joined: Thu May 29, 2008 8:36 am
Post
by <?erick?> » Sun Jun 22, 2008 8:57 pm
hello i got error please see.. please help me to solve this problem.
Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 123
Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 134
Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 173
ragnis12
Forum Newbie
Posts: 12 Joined: Tue Jun 17, 2008 4:14 am
Post
by ragnis12 » Mon Jun 23, 2008 6:06 am
can we see that file?