Hey everyone,
I've just written some basic code to upload a pdf file from a browser to a server. It works fine when I use Firefox, however when I use IE after clicking the upload button it returns to the index page which I just can't figure out.
If anyone has any idea how to fix this could they let me know, thanks!
(it is added to another page which includes mysql_connect() and all that, it is not a mysql problem but a php one)
Here is my code :
[PHP]
<html>
<head>
<title>Brochure s</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="brochures " action="index.p hp?menu=Brochur es&list_all=1" method="post" enctype="multip art/form-data">
<?php
//If user has clicked view/edit brochures, display list
if(!($list_all) ){
$pdfName = $_POST['brochName'];
$pdf = $_FILES['pdfFile']['name'];
$pdfTemp = $_FILES['pdfFile']['tmp_name'];
$pdfDesc = $_POST['descript'];
$query = "INSERT INTO brochures ('field_1','fie ld_2','field_3' ) VALUES ($pdfName,$pdf, $pdfDesc)" or die("Could not upload: ".mysql_error() );
?>
<table width="68%" height="62" border="0">
<tr>
<td width="42%">Nam e:</td>
<td width="58%"><in put name="brochName " type="text" id="brochName2 " value=""></td>
</tr>
<tr>
<td height="26">Bro chure:</td>
<td><input type="file" name="pdfFile" accept="applica tion/pdf"></td>
</tr>
<tr>
<td height="26">&nb sp;</td>
<td><input type="submit" name="SubmitBro chure" value="Upload" class="sumbit"> </td>
</tr>
</table>
<p> </p>
<p><a href="index.php ?menu=Brochures &list_all=1">Vi ew/Edit Brochures</a></p>
<?php
}
//else display this
else{
$q9 = mysql_query("SE LECT * from brochures ORDER BY id ASC");
$numRows = mysql_num_rows( $q9);
echo("<table>") ;
for($i=0;$i<$nu mRows;$i++){
$name = mysql_result($q 9,$i,1);
$file = mysql_result($q 9,$i,2);
$ID = mysql_Result($q 9,$i,0);
echo("<tr><td>< font size=1><a href=\"index.ph p?menu=Brochure s&deleteNAME=$f ile&DID=$ID\">d elete</a></font></td><td><a href=\"../upload/$file\" target=_blank>$ name</a></td></tr>");
}
echo("</table><br><br>< a href=\"index.ph p?menu=Brochure s\">back to New Brochure</a>");
}
if($SubmitBroch ure){
if($_FILES['pdfFile']['type'] == "applicatio n/pdf"){
$add = "../upload/$pdf";
if(!(file_exist s($add))){
if(move_uploade d_file($pdfTemp ,$add)){
mysql_query("IN SERT INTO brochures (field_1,field_ 2) VALUES ('$pdfName','$p df')") or die ("no mysql: ".mysql_error() );
echo("Brochure uploaded");
}
else echo("pdfTemp: $pdfTemp<br>add : $add<br><br>Cou ld not upload file!");
} else echo("The pdf \"".$pdf."\" already exists. Try renaming your pdf before uploading.");
}
else echo("You must select a pdf file to upload!");
}
?>
</form>
<?php
if($deleteNAME) {
echo($deleteNAM E);
unlink("../upload/".$deleteNA ME);
mysql_query("DE LETE FROM brochures WHERE id='$DID'") or die("Did not delete mysql entry: ".mysql_error() );
echo(" was successfully deleted");
}
?>
</body>
</html>
[/PHP]
Cheers
I've just written some basic code to upload a pdf file from a browser to a server. It works fine when I use Firefox, however when I use IE after clicking the upload button it returns to the index page which I just can't figure out.
If anyone has any idea how to fix this could they let me know, thanks!
(it is added to another page which includes mysql_connect() and all that, it is not a mysql problem but a php one)
Here is my code :
[PHP]
<html>
<head>
<title>Brochure s</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="brochures " action="index.p hp?menu=Brochur es&list_all=1" method="post" enctype="multip art/form-data">
<?php
//If user has clicked view/edit brochures, display list
if(!($list_all) ){
$pdfName = $_POST['brochName'];
$pdf = $_FILES['pdfFile']['name'];
$pdfTemp = $_FILES['pdfFile']['tmp_name'];
$pdfDesc = $_POST['descript'];
$query = "INSERT INTO brochures ('field_1','fie ld_2','field_3' ) VALUES ($pdfName,$pdf, $pdfDesc)" or die("Could not upload: ".mysql_error() );
?>
<table width="68%" height="62" border="0">
<tr>
<td width="42%">Nam e:</td>
<td width="58%"><in put name="brochName " type="text" id="brochName2 " value=""></td>
</tr>
<tr>
<td height="26">Bro chure:</td>
<td><input type="file" name="pdfFile" accept="applica tion/pdf"></td>
</tr>
<tr>
<td height="26">&nb sp;</td>
<td><input type="submit" name="SubmitBro chure" value="Upload" class="sumbit"> </td>
</tr>
</table>
<p> </p>
<p><a href="index.php ?menu=Brochures &list_all=1">Vi ew/Edit Brochures</a></p>
<?php
}
//else display this
else{
$q9 = mysql_query("SE LECT * from brochures ORDER BY id ASC");
$numRows = mysql_num_rows( $q9);
echo("<table>") ;
for($i=0;$i<$nu mRows;$i++){
$name = mysql_result($q 9,$i,1);
$file = mysql_result($q 9,$i,2);
$ID = mysql_Result($q 9,$i,0);
echo("<tr><td>< font size=1><a href=\"index.ph p?menu=Brochure s&deleteNAME=$f ile&DID=$ID\">d elete</a></font></td><td><a href=\"../upload/$file\" target=_blank>$ name</a></td></tr>");
}
echo("</table><br><br>< a href=\"index.ph p?menu=Brochure s\">back to New Brochure</a>");
}
if($SubmitBroch ure){
if($_FILES['pdfFile']['type'] == "applicatio n/pdf"){
$add = "../upload/$pdf";
if(!(file_exist s($add))){
if(move_uploade d_file($pdfTemp ,$add)){
mysql_query("IN SERT INTO brochures (field_1,field_ 2) VALUES ('$pdfName','$p df')") or die ("no mysql: ".mysql_error() );
echo("Brochure uploaded");
}
else echo("pdfTemp: $pdfTemp<br>add : $add<br><br>Cou ld not upload file!");
} else echo("The pdf \"".$pdf."\" already exists. Try renaming your pdf before uploading.");
}
else echo("You must select a pdf file to upload!");
}
?>
</form>
<?php
if($deleteNAME) {
echo($deleteNAM E);
unlink("../upload/".$deleteNA ME);
mysql_query("DE LETE FROM brochures WHERE id='$DID'") or die("Did not delete mysql entry: ".mysql_error() );
echo(" was successfully deleted");
}
?>
</body>
</html>
[/PHP]
Cheers
Comment