Avatar billede Slettet bruger
05. januar 2008 - 20:30 Der er 12 kommentarer og
1 løsning

Refresh ifb. med upload

Jeg bøvler lidt med et meget simpelt upload script da jeg er heeelt grøn mht. php

Scriptet virker såmænd fint nok, det gør dét billede galleri som er på samme side også.

Problemet er bare at jeg ønsker siden refresh'et straks jeg har uploaded mit billede således at det ses med det samme og ikke først når jeg har trykker f5

<?php

if (isset($_FILES['filnavn'])) {

$query = "INSERT INTO billeder SET billedenavn='".$_FILES['filnavn']['name']."'";
    $Result1=mysql_query($query, $CookingForSingles) or die(mysql_error());
}

if (isset($_FILES['filnavn'])){
    $tempfile = $_FILES['filnavn']['tmp_name'];
    $destination = "../../billeder/{$_FILES['filnavn']['name']} ";
    copy($tempfile, $destination);
}

?>           
<form action="assetmaneger.php" method="post" enctype="multipart/form-data" name="upload" id="upload">
<input name="filnavn" type="file" id="filnavn" />
<br>
<input name="submit" type="submit" id="submit" value="Upload" />
</form>
Avatar billede jakobdo Ekspert
05. januar 2008 - 21:19 #1
Efter:
copy($tempfile, $destination);
Kan du tilføje:
copy($tempfile, $destination);
header('Location: SIDEN_SOM_SKAL_VISES_EFTER_UPLOAD_AF_BILLEDE.php');
exit();
Avatar billede Slettet bruger
05. januar 2008 - 22:18 #2
Dét bryder den sig ikke om - får denne fejlmeddelse:

Warning: Cannot modify header information - headers already sent by (output started at c:\programmer\easyphp1-8\www\galleri\assetmaneger.php:5) in c:\programmer\easyphp1-8\www\galleri\assetmaneger.php on line 33<--linien i koden
Avatar billede jakobdo Ekspert
05. januar 2008 - 22:22 #3
Hvad har du på linje 5 og linje 33 ?
Avatar billede Slettet bruger
06. januar 2008 - 14:19 #4
Du får lige hele scriptet...

<?php require_once('../Connections/galleri.php');
mysql_select_db($database_galleri, $galleri);
?>

<?php
mysql_select_db($database_galleri, $galleri);
$query_rsBilleder = "SELECT * FROM billeder";
$rsBilleder = mysql_query($query_rsBilleder, $galleri) or die(mysql_error());
$row_rsBilleder = mysql_fetch_assoc($rsBilleder);
$totalRows_rsBilleder = mysql_num_rows($rsBilleder);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Assetmaneger</title>
</head>

<body bgcolor="#EEEEEE" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<?php

if (isset($_FILES['filnavn'])) {

$query = "INSERT INTO billeder SET billedenavn='".$_FILES['filnavn']['name']."'";
    $Result1=mysql_query($query, $galleri) or die(mysql_error());
}

if (isset($_FILES['filnavn'])){
    $tempfile = $_FILES['filnavn']['tmp_name'];
    $destination = "../billeder/{$_FILES['filnavn']['name']} ";
    copy($tempfile, $destination);
        header('Location: assetmaneger.php');
        exit();
   
?>           
<form action="" method="post" enctype="multipart/form-data" name="upload" id="upload">
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Hent billede :</span>
  <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
    <tr>
      <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;"><input name="filnavn" type="file" id="filnavn" />&nbsp;<input name="submit" type="submit" id="submit" style="font-size: 12px" value="Upload" /></td>
    </tr>
  </table>
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Galleri:</span>
<?php do { ?>
  <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
    <tr style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">
      <td width="30%" align="center"><?php echo '<img height="80" width="80" src="../billeder/'.$row_rsBilleder['billedenavn'].'">'; ?></td>
        <td width="30%" align="center"><?php echo $row_rsBilleder['billedenavn']; ?></td>
        <td width="20%" align="center"><a href="#" onClick="window.opener.location.reload();self.close()">Indsæt billede</a></td>
        <td width="20%" align="center"><a href="delete_image.php?sletbilledeid=<?php echo $row_rsBilleder ['billedeid'];?>" onClick="java script: return confirm('Er du sikker på at du vil slette dette billede?');">Slet</a></td>
      </tr>
      </table>
  <?php } while ($row_rsBilleder = mysql_fetch_assoc($rsBilleder)); ?></form>
</body>
</html>
<?php
mysql_free_result($rsBilleder);
?>
Avatar billede jakobdo Ekspert
06. januar 2008 - 17:20 #5
Ryk delen:

<?php

if (isset($_FILES['filnavn'])) {

$query = "INSERT INTO billeder SET billedenavn='".$_FILES['filnavn']['name']."'";
    $Result1=mysql_query($query, $galleri) or die(mysql_error());
}

if (isset($_FILES['filnavn'])){
    $tempfile = $_FILES['filnavn']['tmp_name'];
    $destination = "../billeder/{$_FILES['filnavn']['name']} ";
    copy($tempfile, $destination);
        header('Location: assetmaneger.php');
        exit();
 
?>           
over <DOCTYPE...
Så vil det virke.
Avatar billede Slettet bruger
06. januar 2008 - 19:33 #6
Nu er jeg helt forvirret, jeg kan ikke teste om det virker fordi den giver mig en helt anden fejlmeddelse nu:

Parse error: parse error in c:\programmer\easyphp1-8\www\galleri\popups\assetmaneger.php on line 58

Det er den allersdste linie... ~:[
Avatar billede Slettet bruger
07. januar 2008 - 18:15 #7
Genopbyggede siden forfra...

Har prøver at sætte header ind som anbefalet men uden held!

Warning: Cannot modify header information - headers already sent by (output started at c:\programmer\easyphp1-8\www\galleri\popups\assetmaneger.php:12) in c:\programmer\easyphp1-8\www\galleri\popups\assetmaneger.php on line 24 <--header
Avatar billede jakobdo Ekspert
07. januar 2008 - 20:31 #8
Hvordan ser din fulde kode ud nu?
Avatar billede Slettet bruger
07. januar 2008 - 21:07 #9
<?php require_once('../Connections/galleri.php'); ?>
<?php
mysql_select_db($database_galleri, $galleri);
$query_rsBilleder = "SELECT * FROM billeder ORDER BY billedeid DESC";
$rsBilleder = mysql_query($query_rsBilleder, $galleri) or die(mysql_error());
$row_rsBilleder = mysql_fetch_assoc($rsBilleder);
$totalRows_rsBilleder = mysql_num_rows($rsBilleder);
?><?php require_once('../Connections/galleri.php');
mysql_select_db($database_galleri, $galleri);
?>

<?php

if (isset($_FILES['filnavn'])) {
   
$query = "INSERT INTO billeder SET billedenavn='".$_FILES['filnavn']['name']."'";
    $Result1=mysql_query($query, $galleri) or die(mysql_error());
}

if (isset($_FILES['filnavn'])){
    $tempfile = $_FILES['filnavn']['tmp_name'];
    $destination = "../billeder/{$_FILES['filnavn']['name']} ";
    copy($tempfile, $destination);
    header('Location: assetmaneger.php');
    exit();
}

?>           
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Assetmaneger</title>
</head>

<body bgcolor="#EEEEEE" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<form action="" method="post" enctype="multipart/form-data" name="upload" id="upload">
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Hent billede :</span>
  <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
    <tr>
      <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;"><input name="filnavn" type="file" id="filnavn" />&nbsp;<input name="submit" type="submit" id="submit" style="font-size: 12px" value="Upload" /></td>
    </tr>
  </table>
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Galleri:</span>
  <?php do { ?>
    <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
      <tr style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">
        <td width="30%" align="center"><?php echo '<img height="80" width="80" src="../billeder/'.$row_rsBilleder['billedenavn'].'">'; ?></td>
          <td width="30%" align="center"><?php echo $row_rsBilleder['billedenavn']; ?></td>
          <td width="20%" align="center"><a href="#" onClick="window.opener.location.reload();self.close()">Indsæt billede</a></td>
          <td width="20%" align="center"><a href="delete_image.php?sletbilledeid=<?php echo $row_rsBilleder['billedeid']; ?>" onClick="java script: return confirm('Er du sikker på at du vil slette dette billede?');">Slet</a></td>
      </tr>
        </table>
    <?php } while ($row_rsBilleder = mysql_fetch_assoc($rsBilleder)); ?></form>
</body>
</html>
<?php
mysql_free_result($rsBilleder);
?>
Avatar billede jakobdo Ekspert
07. januar 2008 - 21:23 #10
test denne kode:

<?php
require_once('../Connections/galleri.php');
mysql_select_db($database_galleri, $galleri);
$query_rsBilleder = "SELECT * FROM billeder ORDER BY billedeid DESC";
$rsBilleder = mysql_query($query_rsBilleder, $galleri) or die(mysql_error());
$row_rsBilleder = mysql_fetch_assoc($rsBilleder);
$totalRows_rsBilleder = mysql_num_rows($rsBilleder);
require_once('../Connections/galleri.php');
mysql_select_db($database_galleri, $galleri);
if (isset($_FILES['filnavn'])) {
    $query = "INSERT INTO billeder SET billedenavn='".$_FILES['filnavn']['name']."'";
    $Result1=mysql_query($query, $galleri) or die(mysql_error());
}

if (isset($_FILES['filnavn'])){
    $tempfile = $_FILES['filnavn']['tmp_name'];
    $destination = "../billeder/{$_FILES['filnavn']['name']} ";
    copy($tempfile, $destination);
    header('Location: assetmaneger.php');
    exit();
}

?>         
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Assetmaneger</title>
</head>

<body bgcolor="#EEEEEE" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<form action="" method="post" enctype="multipart/form-data" name="upload" id="upload">
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Hent billede :</span>
  <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
    <tr>
      <td style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;"><input name="filnavn" type="file" id="filnavn" />&nbsp;<input name="submit" type="submit" id="submit" style="font-size: 12px" value="Upload" /></td>
    </tr>
  </table>
<span style="font-family: arial, verdana, helvetica; font-size: 11px; font-weight: bold;">Galleri:</span>
  <?php do { ?>
    <table width="380" border="0" cellpadding="0" cellspacing="0" style="background-color: #F7F7F7; border: 2px solid #FFFFFF; padding: 5px;">
      <tr style="padding-bottom: 2px; padding-top: 0px; font-family: arial, verdana, helvetica; font-size: 11px;">
        <td width="30%" align="center"><?php echo '<img height="80" width="80" src="../billeder/'.$row_rsBilleder['billedenavn'].'">'; ?></td>
          <td width="30%" align="center"><?php echo $row_rsBilleder['billedenavn']; ?></td>
          <td width="20%" align="center"><a href="#" onClick="window.opener.location.reload();self.close()">Indsæt billede</a></td>
          <td width="20%" align="center"><a href="delete_image.php?sletbilledeid=<?php echo $row_rsBilleder['billedeid']; ?>" onClick="java script: return confirm('Er du sikker på at du vil slette dette billede?');">Slet</a></td>
      </tr>
        </table>
    <?php } while ($row_rsBilleder = mysql_fetch_assoc($rsBilleder)); ?></form>
</body>
</html>
<?php
mysql_free_result($rsBilleder);
?>
Avatar billede Slettet bruger
07. januar 2008 - 22:31 #11
YES! så var den der... smid et svar... ~:]
Avatar billede jakobdo Ekspert
08. januar 2008 - 22:02 #12
Svar!
Avatar billede jakobdo Ekspert
09. januar 2008 - 20:03 #13
Takker for point.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester