Forums
This topic is locked
php uploader
Posted 05 Aug 2006 08:11:15
1
has voted
05 Aug 2006 08:11:15 Mark Matthews posted:
I've been trying to install a (few) file uploading script(s) to my site and can't seem to get it to work. Do the .php files need to be inside the uploads folder or the main directory? I would actually prefer to send the user a link via email to the upload page as opposed to having it on the site. Is there a script anyone would recommend? I only need to be able to upload one file (mp3) at a time. Thanks for any help.Mark
Replies
Replied 07 Aug 2006 13:20:30
07 Aug 2006 13:20:30 Roddy Dairion replied:
<pre id=code><font face=courier size=2 id=code>
if ($_POST['Submit'] == "Upload"
{
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
And this is my form
<pre id=code><font face=courier size=2 id=code>
<form name="upload" method="post" enctype="multipart/form-data">
<table width="40%" height="161" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Files: </td>
<td><input type="file" name="txt_upload" class="input"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</form>
</font id=code></pre id=code>
Hope it helps.
if ($_POST['Submit'] == "Upload"
{
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
And this is my form
<pre id=code><font face=courier size=2 id=code>
<form name="upload" method="post" enctype="multipart/form-data">
<table width="40%" height="161" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Files: </td>
<td><input type="file" name="txt_upload" class="input"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</form>
</font id=code></pre id=code>
Hope it helps.
Replied 23 Aug 2006 06:42:26
23 Aug 2006 06:42:26 LorD ExoskeletoN replied:
Your code sir is perfect...thank you its a big help..
sir one more thing, i already know how to upload files...but how can i retrieve them?
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<pre id=code><font face=courier size=2 id=code>
if ($_POST['Submit'] == "Upload"
{
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
And this is my form
<pre id=code><font face=courier size=2 id=code>
<form name="upload" method="post" enctype="multipart/form-data">
<table width="40%" height="161" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Files: </td>
<td><input type="file" name="txt_upload" class="input"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</form>
</font id=code></pre id=code>
Hope it helps.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
sir one more thing, i already know how to upload files...but how can i retrieve them?
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<pre id=code><font face=courier size=2 id=code>
if ($_POST['Submit'] == "Upload"
{
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
And this is my form
<pre id=code><font face=courier size=2 id=code>
<form name="upload" method="post" enctype="multipart/form-data">
<table width="40%" height="161" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Files: </td>
<td><input type="file" name="txt_upload" class="input"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</form>
</font id=code></pre id=code>
Hope it helps.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 23 Aug 2006 06:49:38
23 Aug 2006 06:49:38 LorD ExoskeletoN replied:
ok the code just run smoothly sir,..ive tried it. but is it possible to store the files in a database?
coz i just site a folder on the path...what if i want to save file in a mysql database..please help...
coz i just site a folder on the path...what if i want to save file in a mysql database..please help...
Replied 23 Aug 2006 11:44:18
23 Aug 2006 11:44:18 Roddy Dairion replied:
ok 1st thing don't call me sir <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> . 2nd of all yes it can be done. withing the if statement just created your insert query like this.
<pre id=code><font face=courier size=2 id=code>
if ($_POST['Submit'] == "Upload"
{
//connection to your mysql database
mysql_connect("your server", "username", "password"
mysql_select_db("databasename"
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
//here just create you mysql insert query
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
<pre id=code><font face=courier size=2 id=code>
if ($_POST['Submit'] == "Upload"
{
//connection to your mysql database
mysql_connect("your server", "username", "password"
mysql_select_db("databasename"
//change this to the path where you want you files to be uploaded
$path='path where your page will be uploaded';
$uploaddir = $path;
$uploadfile = $uploaddir . $_FILES['txt_upload']['name'];
if (move_uploaded_file($_FILES['txt_upload']['tmp_name'], $uploadfile))
{
//here just create you mysql insert query
echo "Files uploaded";
}
else
{
echo "Files not Uploaded";
}
}
</font id=code></pre id=code>
Replied 24 Aug 2006 09:02:09
24 Aug 2006 09:02:09 LorD ExoskeletoN replied:
OK...i forgot to ask if what data type im going to use in mysql database if im goin to upload an image or somekind of text files sir, i mean what can i call you sir?
But thank you very much...I know it will work...ok i will try it now. Wait what about the path, is it still necessary to map the folder's location just like the first example you've given without the database?
after this topic...is it ok to ask you again, on how to display the images being uploaded?
hope its ok with you sir...
Edited by - exoskeleton on 24 Aug 2006 09:10:11
Edited by - exoskeleton on 24 Aug 2006 09:20:20
But thank you very much...I know it will work...ok i will try it now. Wait what about the path, is it still necessary to map the folder's location just like the first example you've given without the database?
after this topic...is it ok to ask you again, on how to display the images being uploaded?
hope its ok with you sir...
Edited by - exoskeleton on 24 Aug 2006 09:10:11
Edited by - exoskeleton on 24 Aug 2006 09:20:20
Replied 24 Aug 2006 12:18:58
24 Aug 2006 12:18:58 Roddy Dairion replied:
within the code add this
<pre id=code><font face=courier size=2 id=code>
$filename = $_FILES['txt_upload']['name'];
</font id=code></pre id=code>
then in you sql query put it in the fieldname where you store filenames. after that create a repeat region, and add this
<pre id=code><font face=courier size=2 id=code>
$path = "path to the files";
//this should be same as the $path in the fileupload script
$retrieve = $path.$row['fieldname'];
</font id=code></pre id=code>
or any alternative option to get all the files in this folder is to use this script
<pre id=code><font face=courier size=2 id=code>
$path = "path to you file";
//e.g. /home/web/files/image/
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path"
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "list.php"
continue;
echo "<a href=\"$file\" target=_blank>$file</a><br><br>";
}
// Close
closedir($dir_handle);
</font id=code></pre id=code>
this one will retrieve all the file withing this folder so you have to make sure that
1.You only have you're uploaded files in this folder
2.save the page.php with this script in the same folder where the images has been uploaded.
<pre id=code><font face=courier size=2 id=code>
$filename = $_FILES['txt_upload']['name'];
</font id=code></pre id=code>
then in you sql query put it in the fieldname where you store filenames. after that create a repeat region, and add this
<pre id=code><font face=courier size=2 id=code>
$path = "path to the files";
//this should be same as the $path in the fileupload script
$retrieve = $path.$row['fieldname'];
</font id=code></pre id=code>
or any alternative option to get all the files in this folder is to use this script
<pre id=code><font face=courier size=2 id=code>
$path = "path to you file";
//e.g. /home/web/files/image/
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path"
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "list.php"
continue;
echo "<a href=\"$file\" target=_blank>$file</a><br><br>";
}
// Close
closedir($dir_handle);
</font id=code></pre id=code>
this one will retrieve all the file withing this folder so you have to make sure that
1.You only have you're uploaded files in this folder
2.save the page.php with this script in the same folder where the images has been uploaded.