PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > with file upload
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with file upload

Réponse
 
LinkBack Outils de la discussion
Vieux 25/07/2007, 01h47   #1
Ralph H. Stoos Jr.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with file upload

All,

I am trying to find a PHP page/script to upload multiple files to a
server for processing. I realize this could be done with a recursive
HTML page too, but I really want this app to be PHP end to end.

I don't really care about cute, what I really want is to have it open a
browse box so the user can select a group of files and then it uploads
them all.

Many of the ones I have seen are almost too configurable. They put in
size limits or filters on a specific file extension etc. I plan to do
all the housekeeping after the files are there.

Ideas?

Ralph
  Réponse avec citation
Vieux 25/07/2007, 02h10   #2
up2trouble
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with file upload

This is what I use. It is simple and I don't know if it is secure,
but it works.

<?PHP
if(isset($_POST['upload_file']))
{
$uploaddir = "./documents/";
$user = $_POST['user'];
$name = $_POST['name'];
$category = $_POST['category'];
$type = $_POST['type'];

$file_name = $_FILES['uploadedfile']['name'];
$file_tmp_name = $_FILES['uploadedfile']['tmp_name'];
$file_name = stripslashes($file_name);
$file_name = preg_replace("#[ ]#","_",$file_name);
$file_name = preg_replace('#[^()\.\-,\w]#','_',$file_name);
$file_name = preg_replace('#(_)+#','_',$file_name);

if (move_uploaded_file($file_tmp_name, $uploaddir.$file_name))
{
echo "<CENTER><FONT SIZE='+1'>File was successfully uploaded.</FONT></
CENTER>";
}
$sql5 = "INSERT INTO $db_table5 (user, name, category, type) VALUES
('$user','$name', '$category', '$type')";
mysql_query ($sql5) or die(mysql_error());
}
?>
<DIV ID="wrapper">
<DIV ID="header">
<?PHP include("includes/header.txt")?>
</DIV>
<DIV ID="subheader">
<?PHP include("includes/navigation.txt")?>
</DIV>
<DIV ID="content">
<H2>Download Document</H2>
<?PHP
$sql = "SELECT * FROM $db_table5 ORDER BY category ASC";
$result = mysql_query ($sql, $connect) or die ('Query failed:
' .mysql_error());
echo "<TABLE CELLSPACING='5' CELLPADDING='2' BORDER='1'>";
echo "<TR><TD CLASS='title'>Category</TD><TD CLASS='title'>Document</
TD><TD CLASS='title'>Type</TD></TR>";
while ($row = mysql_fetch_array($result))
{
$category = $row['category'];
$sql2 = "SELECT * FROM $db_table6 WHERE id = '$category'";
$result2 = mysql_query($sql2)OR die ('I crashed because: ' .
mysql_error());
while ($row2 = mysql_fetch_array($result2))
{
$name2 = $row2['name'];
}
$name = $row['name'];
$url = $row['url'];
$type = $row['type'];
echo "<TR><TD>$name2</TD><TD><A CLASS='mnav' HREF='http://
bainbridge.stagingspace.net/documents/$url' ALT='$name' TARGET='_top'>
$name</A></TD><TD>$type</TD></TR>";
}
echo "</TABLE>";
?>
<BR>
<H2>Upload Document</H2>
<FORM ACTION="documents.php" METHOD="post" ENCTYPE="multipart/form-
data">
<TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0">
<TR>
<TD CLASS='title'>Posted By:</TD>
<TD><INPUT TYPE="text" NAME="user" SIZE="35" MAXLENGTH="25"></TD>
</TR>
<TR>
<TD CLASS='title'>File Name:</TD>
<TD><INPUT TYPE="text" NAME="name" SIZE="35" MAXLENGTH="50"></TD>
</TR>
<TR>
<TD CLASS='title'>Category:</TD>
<TD>
<SELECT NAME='category'>
<OPTION VALUE='0' SELECTED>--- Select Category ---</OPTION>
<?PHP
$sql = "SELECT * FROM $db_table6 ORDER BY name";
$result = mysql_query ($sql, $connect) or die ('Query failed:
' .mysql_error());
while ($row = mysql_fetch_array ($result))
{
$id = $row["id"];
$name = $row["name"];
echo "<OPTION VALUE='$id'>$name</OPTION>";
}
?>
</SELECT>
</TD>
</TR>
<TR>
<TD CLASS='title'>Type:</TD>
<TD>
<SELECT NAME="type" SIZE="1">
<OPTION VALUE='0' SELECTED>--- Select Type ---</OPTION>
<OPTION VALUE="pdf">pdf</OPTION>
<OPTION VALUE="doc">doc</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD CLASS='title'>File:</TD>
<TD>
<INPUT TYPE="file" NAME="uploadedfile" SIZE="35">
</TD>
</TR>
<TR>
<TD COLSPAN="2">
<BR>
<INPUT TYPE="submit" NAME="upload_file" VALUE="Upload Document">
</TD>
</TR>
</TABLE>
</DIV>


  Réponse avec citation
Vieux 25/07/2007, 11h08   #3
C.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with file upload

On 25 Jul, 01:47, "Ralph H. Stoos Jr." <rst...@rochester.rr.com>
wrote:
> All,
>
> I am trying to find a PHP page/script to upload multiple files to a
> server for processing. I realize this could be done with a recursive
> HTML page too,


Eh? How?

> but I really want this app to be PHP end to end.
>
> I don't really care about cute, what I really want is to have it open a
> browse box so the user can select a group of files and then it uploads
> them all.
>


What you are describing is not possible - browsers only allow users to
select one file at a time - but you can have multiple file input
fields on / submissions from a single web page.

> Many of the ones I have seen are almost too configurable. They put in
> size limits or filters on a specific file extension etc. I plan to do
> all the housekeeping after the files are there.
>


So your system is isolated from the internet and you trust your users
100% and you will be storing your files where they are not directly
accesible by the webserver / using a custom directory with non-
standard mime mappings to store the files.

I think you are not understanding what you are asking for.

C.

  Réponse avec citation
Vieux 25/07/2007, 13h57   #4
vic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with file upload


"Ralph H. Stoos Jr." <rstoos@rochester.rr.com> wrote in message
news:46a69db0$0$4704$4c368faf@roadrunner.com...
> All,
>
> I am trying to find a PHP page/script to upload multiple files to a server
> for processing. I realize this could be done with a recursive HTML page
> too, but I really want this app to be PHP end to end.
>
> I don't really care about cute, what I really want is to have it open a
> browse box so the user can select a group of files and then it uploads
> them all.
>
> Many of the ones I have seen are almost too configurable. They put in
> size limits or filters on a specific file extension etc. I plan to do all
> the housekeeping after the files are there.
>
> Ideas?
>
> Ralph



Put all of the files to upload into a zip file and upload the single file.
This method will be faster because of compression .

Vic

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h10.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11302 seconds with 12 queries