Add Games
Webtijn - 29/07/2005 20:27
PHP interesse
Ik heb weer eens zo'n script met zo'n lekkere error.
De error is:
Warning: unlink(../screenshot/): Operation not permitted in /usr/export/www/hosting/webtijn/SpelCity/admin/spellen_toevoegen.php on line 54
(Een error die ik dus echt nog nooit heb gezien)
De code:
<td width="100%" align="center">
<form action="" method="post">
<table width="440">
<tr>
<td width="178">Naam:</td>
<td width="250"><input type="text" name="name" maxlength="20"></td>
</tr>
<tr>
<td width="178">Categorie:</td>
<td width="250">
<select name="cat">
<option value=1>18+</option>
<option value=2>Avontuur</option>
<option value=3>Sport</option>
<option value=4>Actie</option>
<option value=5>Multiplayer</option>
<option value=6>Denk</option>
<option value=7>Race</option>
<option value=8>Behendigheid</option>
<option value=9>Overig</option>
</select>
</td>
</tr>
<tr>
<td width="178">Width:</td>
<td width="250"><input type="text" name="width"></td>
</tr>
<tr>
<td width="178">Height:</td>
<td width="250"><input type="text" name="height"></td>
</tr>
<tr>
<td width="178">Url:</td>
<td width="250"><input type="text" name="url"></td>
</tr>
<tr>
<td width="178">Screenshot:</td>
<td width="250"><input class="forTexts" type="file" name="upfile" id="upfile" size"20"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
<?PHP
include('config.php');
if(!isset($_POST['submit'])) {
echo '';
}else{
$query = "INSERT INTO `gm_games` (`id`, `cat`, `name`, `screenshot`, `width`, `height`, `url`, `views`) VALUES (' " . $_POST['id'] . " ', ' " . $_POST['cat'] . " ', ' " . $_POST['name'] . " ', ' " .$map.$_FILES['upfile']['name'] . " ', ' " . $_POST['width'] . " ', ' " . $_POST['height'] . " ', ' " . $_POST['url'] . " ', ' " . $_POST['vieuws'] . " ')";
mysql_query($query) or die(mysql_error());
if (file_exists($map.$_FILES['upfile']['name'])) {
unlink($map.$_FILES['upfile']['name']);
}
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
move_uploaded_file($_FILES['upfile']['tmp_name'], $map.$_FILES['upfile']['name']);
echo 'De game is succesvol toegevoegd!';
}
}
?>
<td width="100%" align="center">
<form action="" method="post">
<table width="440">
<tr>
<td width="178">Naam:</td>
<td width="250"><input type="text" name="name" maxlength="20"></td>
</tr>
<tr>
<td width="178">Categorie:</td>
<td width="250">
<select name="cat">
<option value=1>18+</option>
<option value=2>Avontuur</option>
<option value=3>Sport</option>
<option value=4>Actie</option>
<option value=5>Multiplayer</option>
<option value=6>Denk</option>
<option value=7>Race</option>
<option value=8>Behendigheid</option>
<option value=9>Overig</option>
</select>
</td>
</tr>
<tr>
<td width="178">Width:</td>
<td width="250"><input type="text" name="width"></td>
</tr>
<tr>
<td width="178">Height:</td>
<td width="250"><input type="text" name="height"></td>
</tr>
<tr>
<td width="178">Url:</td>
<td width="250"><input type="text" name="url"></td>
</tr>
<tr>
<td width="178">Screenshot:</td>
<td width="250"><input class="forTexts" type="file" name="upfile" id="upfile" size"20"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
<?PHP
include ( 'config.php' ) ;
if ( ! isset ( $_POST [ 'submit' ] ) ) { } else {
$query = "INSERT INTO `gm_games` (`id`, `cat`, `name`, `screenshot`, `width`, `height`, `url`, `views`) VALUES (' " . $_POST [ 'id' ] . " ', ' " . $_POST [ 'cat' ] . " ', ' " . $_POST [ 'name' ] . " ', ' " . $map . $_FILES [ 'upfile' ] [ 'name' ] . " ', ' " . $_POST [ 'width' ] . " ', ' " . $_POST [ 'height' ] . " ', ' " . $_POST [ 'url' ] . " ', ' " . $_POST [ 'vieuws' ] . " ')" ;
unlink ( $map . $_FILES [ 'upfile' ] [ 'name' ] ) ; }
echo 'De game is succesvol toegevoegd!' ; }
}
?>
Wie o wie weet hoe ik deze error oplos?
8 antwoorden
Gesponsorde links
Webtijn - 29/07/2005 20:32
PHP interesse
:P, hij moet geen screenshots gaan verwijderen maar toevoegen.
Weet iemand anders misschien wel een 'klein' script waarmee ik afbeeldingen kan uploaden? Want in de script libery staan van die gigantische scripts met max grote enz.
TFOL - 30/07/2005 00:35 (laatste wijziging 30/07/2005 00:36)
PHP beginner
wil je een simpel upload scriptje voor screenshots/foto's?
dat zal ik wel ffies voor je scripten
<?php
error_reporting(E_ALL);
$locatie = "mapnaam_waar_fotos_naar_toe_moeten";
?>
<html>
<head>
<title>Simpel uploader</title>
</head>
<body>
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="foto"/><br /><br />
<input type="submit" name="verzenden" value="Verzenden!"/>
</form>
<?php
if(isset($_POST['verzenden']))
{
$foto = $_FILES['foto']['name'];
$tmp_foto = $_FILES['foto']['tmp_name'];
if(move_uploaded_file($tmp_foto, $locatie."/".$foto))
{
echo "Foto is succesvol verzonden";
}
else
{
echo "Foto kon niet worden verzonden";
}
}
?>
</body>
</html>
<?php
$locatie = "mapnaam_waar_fotos_naar_toe_moeten" ;
?>
<html>
<head>
<title>Simpel uploader</title>
</head>
<body>
<form method="POST" action="" enctype="multipart/form-data">
<input type="file" name="foto"/><br /><br />
<input type="submit" name="verzenden" value="Verzenden!"/>
</form>
<?php
if ( isset ( $_POST [ 'verzenden' ] ) ) {
$foto = $_FILES [ 'foto' ] [ 'name' ] ;
$tmp_foto = $_FILES [ 'foto' ] [ 'tmp_name' ] ;
{
echo "Foto is succesvol verzonden" ; }
else
{
echo "Foto kon niet worden verzonden" ; }
}
?>
</body>
</html>
veel plezier
:cool:
Thomas - 30/07/2005 11:25
Moderator
Dat if-statement met die file_exists controleert of op de plaats van bestemming al een plaatje met de upload-naam bestaat, zoja, dan wordt dit (oude) plaatje eerst verwijderd.
Dit is echter niet nodig, omdat move_uploaded_file() plaatjes met dezelfde naam gewoon overschrijft, dus dat hele if-statement kan weg (php.net : If the destination file already exists, it will be overwritten).
Je moet inderdaad wel zorgen dat je (directory-)permissies goed staan.
Webtijn - 30/07/2005 13:11 (laatste wijziging 30/07/2005 13:13)
PHP interesse
Oke, nou ik heb het script weer een beetje kunnen fixen.
Met de nadruk op beetje
Want nu kom ik met het volgende probleem:
Mijn site: http://www.mijnsite.nl /
Admin panel: http://www.mijnsite.nl/admin /
Nu staat add.php (spellen toevoegen) in admin.
Dit is de code:
<?
include("config.php");
ob_start();
if ($action == "verwijderen") {
$sql = "DELETE FROM `gm_games` WHERE id = '".$_GET['id']."'";
mysql_query($sql) or die(mysql_error());
echo "<meta http-equiv=\"refresh\" content=\"1;URL=index.php?p=add&action=begin\">";
echo "Verwijdert!";
}
elseif ($action == "toevoegen") {
if ($_POST['toevoegen']) {
if (file_exists($map.$_FILES['upfile']['name'])) {
unlink($map.$_FILES['upfile']['name']);
}
if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
move_uploaded_file($_FILES['upfile']['tmp_name'], $map.$_FILES['upfile']['name']);
$query = "INSERT into `gm_games` (id, cat, name, screenshot, width, height, url) VALUES ('','".$_POST['cat']."','".$_POST['name']."','".$map.$_FILES['upfile']['name']."','".$_POST['width']."','".$_POST['height']."','".$_POST['url']."')";
mysql_query($query) or die(mysql_error());
echo "De game is succesvol toegevoegd!";
} else {
echo "Er ging iets fout bij het uploaden!";
}
}
else {
echo "<form action=\"index.php?p=portfolio_beheer&action=toevoegen\" enctype=\"multipart/form-data\" name=\"upfile\" method=\"POST\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"178\">Naam:</td>";
echo "<td width=\"250\"><input type=\"text\" name=\"name\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"178\">Categorie:</td>";
echo "<td width=\"250\">";
echo "<select name=\"cat\">";
echo "<option value=1>18+</option>";
echo "<option value=2>Avontuur</option>";
echo "<option value=3>Sport</option>";
echo "<option value=4>Actie</option>";
echo "<option value=5>Multiplayer</option>";
echo "<option value=6>Denk</option>";
echo "<option value=7>Race</option>";
echo "<option value=8>Behendigheid</option>";
echo "<option value=9>Overig</option>";
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"178\">Width:</td>";
echo "<td width=\"250\"><input type=\"text\" name=\"width\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"178\">Height:</td>";
echo "<td width=\"250\"><input type=\"text\" name=\"height\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"178\">Url:</td>";
echo "<td width=\"250\"><input type=\"text\" name=\"url\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\" class=\"forTexts\">Screen:</td>";
echo "<td width=\"50%\" class=\"forTexts\"><input type=\"file\" name=\"upfile\" id=\"upfile\" size=\"20\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\" class=\"forTexts\"> </td>";
echo "<td width=\"50%\" class=\"forTexts\">";
echo "<br><input type=\"submit\" value=\"Toevoegen\" name=\"toevoegen\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"100%\" class=\"forTexts\" colspan=\"2\"><a href=\"javascript:history.go(-1);\">Ga terug</a></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
}
// End
else {
?>
<?
}
ob_end_flush();
?>
</body>
</html>
<?
include ( "config.php" ) ;
if ( $action == "verwijderen" ) {
$sql = "DELETE FROM `gm_games` WHERE id = '" . $_GET [ 'id' ] . "'" ;
echo "<meta http-equiv=\" refresh\" content=\" 1;URL=index.php?p=add&action=begin\" >" ; }
elseif ( $action == "toevoegen" ) {
if ( $_POST [ 'toevoegen' ] ) {
unlink ( $map . $_FILES [ 'upfile' ] [ 'name' ] ) ; }
$query = "INSERT into `gm_games` (id, cat, name, screenshot, width, height, url) VALUES ('','" . $_POST [ 'cat' ] . "','" . $_POST [ 'name' ] . "','" . $map . $_FILES [ 'upfile' ] [ 'name' ] . "','" . $_POST [ 'width' ] . "','" . $_POST [ 'height' ] . "','" . $_POST [ 'url' ] . "')" ;
echo "De game is succesvol toegevoegd!" ; } else {
echo "Er ging iets fout bij het uploaden!" ; }
}
else {
echo "<form action=\" index.php?p=portfolio_beheer&action=toevoegen\" enctype=\" multipart/form-data\" name=\" upfile\" method=\" POST\" >" ; echo "<table border=\" 0\" cellpadding=\" 0\" cellspacing=\" 0\" width=\" 100%\" >" ; echo "<td width=\" 178\" >Naam:</td>" ; echo "<td width=\" 250\" ><input type=\" text\" name=\" name\" ></td>" ; echo "<td width=\" 178\" >Categorie:</td>" ; echo "<td width=\" 250\" >" ; echo "<select name=\" cat\" >" ; echo "<option value=1>18+</option>" ; echo "<option value=2>Avontuur</option>" ; echo "<option value=3>Sport</option>" ; echo "<option value=4>Actie</option>" ; echo "<option value=5>Multiplayer</option>" ; echo "<option value=6>Denk</option>" ; echo "<option value=7>Race</option>" ; echo "<option value=8>Behendigheid</option>" ; echo "<option value=9>Overig</option>" ; echo "<td width=\" 178\" >Width:</td>" ; echo "<td width=\" 250\" ><input type=\" text\" name=\" width\" ></td>" ; echo "<td width=\" 178\" >Height:</td>" ; echo "<td width=\" 250\" ><input type=\" text\" name=\" height\" ></td>" ; echo "<td width=\" 178\" >Url:</td>" ; echo "<td width=\" 250\" ><input type=\" text\" name=\" url\" ></td>" ; echo "<td width=\" 50%\" class=\" forTexts\" >Screen:</td>" ; echo "<td width=\" 50%\" class=\" forTexts\" ><input type=\" file\" name=\" upfile\" id=\" upfile\" size=\" 20\" ></td>" ; echo "<td width=\" 50%\" class=\" forTexts\" > </td>" ; echo "<td width=\" 50%\" class=\" forTexts\" >" ; echo "<br><input type=\" submit\" value=\" Toevoegen\" name=\" toevoegen\" ></td>" ; echo "<td width=\" 100%\" class=\" forTexts\" colspan=\" 2\" ><a href=\" javascript:history.go(-1);\" >Ga terug</a></td>" ; }
}
// End
else {
?>
<?
}
?>
</body>
</html>
En in de config staat nu:
$map = "../screenshot/"; // screenshots
Maar nu upload hij naar ../screenshot/ en zet hij in de db:
../screenshot/plaatje.extentie.
Het probleem is nu dat op de index linkt hij ook meteen naar ../screenshot terwijl het vanuit index moet zijn: /screenshot/plaatje.extentie.
Hoe los ik dat probleem op?
Edit
Ik heb de hele code gepost maar het gaat om toevoegen.
Thomas - 30/07/2005 14:43
Moderator
Werk vanuit de root ?
Gebruik "/screenshot/" of "./screenshot/" ?
Webtijn - 30/07/2005 20:11
PHP interesse
Dat is juist het probleem, ik gebruik ../screenshot/ alleen hij zet datzelfde ook in de db. dus dan probeert hij vanaf de index ook ../ te doen maar dat kan natuurlijk niet. dan meot het zijn /screenshot/ maar hoe pas ik het script zo aan dat ik kan instellen wat hij in de db moet invoegen? dus in plaats van ../ maar: /
Gesponsorde links
Dit onderwerp is gesloten .