Upload script, helemaal gratis!
Ik open het script en mijn oog valt al meteen op onnodige code:
Codeblok (Regel 3/4):
1
2
$result = mysql_query("SELECT * FROM upload");
$num_rows = mysql_num_rows($result);
Waarom alles ophalen als je toch alleen de count wil?
Codeblok (index.php - regel 3/4):
1
2
$result = mysql_query("SELECT 1 FROM upload");
$num_rows = mysql_num_rows($result);
Codeblok (index.php - regel 13):
1
echo ""."$num_rows"."";?>
Waarom "". " gebruiken?
Codeblok (index.php - regel 13):
1
echo $num_rows; ?>
Hetzelfde met je header.php, daar heb je met sitenaam
ipv
Verde heb ik er niet echt naar gekeken, omdat het rommelige indenting heeft. Dit zou ik ook even aanpassen. Dit script aanpassen zoals het er nu uit ziet is namelijk een hel om te doen.
Zie dit niet als zomaar kritiek, maar als opbouwende kritiek.
upload_file ziet er dan zo uit, veel leesbaarder mijns inziens (mogelijk zitten er nog spaties in van oude code. Dan is de indenting alsnog fucked up):
Codeblok (Regel 3/4):
1
2
$result = mysql_query("SELECT * FROM upload");
$num_rows = mysql_num_rows($result);
Waarom alles ophalen als je toch alleen de count wil?
Codeblok (index.php - regel 3/4):
1
2
$result = mysql_query("SELECT 1 FROM upload");
$num_rows = mysql_num_rows($result);
Codeblok (index.php - regel 13):
1
echo ""."$num_rows"."";?>
Waarom "". " gebruiken?
Codeblok (index.php - regel 13):
1
echo $num_rows; ?>
Hetzelfde met je header.php, daar heb je met sitenaam
<title>[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]""[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$sitenaam[/COLOR] [COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR] ?></title> ipv
<title>[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$sitenaam[/COLOR][COLOR= #007700];[/COLOR] ?></title> Verde heb ik er niet echt naar gekeken, omdat het rommelige indenting heeft. Dit zou ik ook even aanpassen. Dit script aanpassen zoals het er nu uit ziet is namelijk een hel om te doen.
Zie dit niet als zomaar kritiek, maar als opbouwende kritiek.

upload_file ziet er dan zo uit, veel leesbaarder mijns inziens (mogelijk zitten er nog spaties in van oude code. Dan is de indenting alsnog fucked up):
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]includes/header.php[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]includes/config.php[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$fileAllowed[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]image/gif[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]image/jpeg[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]image/pjpeg[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]image/png[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/in_array"]in_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"type"[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$fileAllowed[/COLOR][COLOR= #007700]) && ([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"size"[/COLOR][COLOR= #007700]] <[/COLOR] [COLOR= #0000BB]30000[/COLOR][COLOR= #007700]))
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"error"[/COLOR][COLOR= #007700]] >[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Return Code: "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"error"[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]"<br />"[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO upload (nummer, naam) VALUES (, "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]")"[/COLOR][COLOR= #007700]);[/COLOR]
?>
<div id="box">
<div id="thumbnailheader" style="margin-left: 120px">
<h1>Bestand geupload!</h1>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$link[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"/"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?>" data-text="[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$tweettekst[/COLOR][COLOR= #007700];[/COLOR] ?>" data-lang="nl" data-size="[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$buttonformaat[/COLOR][COLOR= #007700];[/COLOR] ?>" data-count="none">Tweeten</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><br /><br />
</div>
<div id="thumbnail" style="float: left; margin-top: -75px;">
<a href=#vb><img src=[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"/"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?> width=100px height=85px></a>;
</div><br /><br />
<table style=width: 100%>";
<tr>
<td style=padding: 0px; vertical-align: top;><strong>Naam:</strong></td>
<td>[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
</tr>
<tr>
<td style=padding: 0px; vertical-align: top;><strong>Type:</strong></td>
<td>[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"type"[/COLOR][COLOR= #007700]];[/COLOR] ?></td>
</tr>
<tr>
<td style=padding: 0px; vertical-align: top;><strong>Grootte:</strong></td>
<td>[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"size"[/COLOR][COLOR= #007700]][/COLOR] / [COLOR= #0000BB]1024[/COLOR][COLOR= #007700]);[/COLOR] ?> Kb</td>
</tr>
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]""[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"/"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]]))
{[/COLOR]
?>
<tr>
<td style=padding: 0px;><strong>Directe link:</strong></td>
<td> <input type=text onclick="this.focus();this.select();" value=[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$link[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"/"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?>/></td>
</tr>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/move_uploaded_file"]move_uploaded_file[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"tmp_name"[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]"/"[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]]);[/COLOR]
?>
<tr>
<td style=padding: 0px;><strong>Directe link:</strong></td>
<td> <input type=text onclick="this.focus();this.select();" value=[COLOR= #0000BB]<?[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$link[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]/[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?>/></td>
</tr>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
</table><br />
<div id="vb">
<strong>Voorbeeld:</strong><br />
<a id="example2" href="[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]/[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR] ?>">
<img alt="example2" src=[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$_FILES[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"file"[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]"name"[/COLOR][COLOR= #007700]];[/COLOR]?> width=100% height=75%>
</a><br /><br />
<input type="button" value="Terug" onClick="parent.location=index.php">
</div>
</div>
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]includes/footer.php[/COLOR][COLOR= #007700];
}
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>
<div id="box">
<h1>Uploaden mislukt!</h1>
Bestand te groot, een verkeerd bestandstype of je hebt helemaal niets geupload! <br /><br />
<input type="button" value="Terug" onClick="parent.location=index.php">
</div>
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/include"]include[/URL] [COLOR= #DD0000]includes/footer.php[/COLOR][COLOR= #007700];
}[/COLOR]
?>Janm schreef:Mijn IDE (Integrated development environment) zorgt daar enigzins zelf voor. Maar als ik op tab druk insert hij als het goed is ook 4 spaties. Dit is de algemene standaard in zon beetje elke programmeertaal.@Rik bedankt, ik ga er aan werken.
Hoe heb je dat trouwens zo uitgelijnd gekregen? Heb je daar een tool voor of heb je dat gewoon aangeleerd?
Dus na elke { indent je 4 naar rechts, en bij elke } keer je weer terug naar dat level:
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]( ... ) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]iets[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]( ... ) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]iets 2[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]oh hallo[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]hallo 2[/COLOR][COLOR= #007700];[/COLOR]
?> Er bestaat daar ook een plugin voor in notepad++
Gebruik bij het invoegen in de DB ook mysql_real_escape_string
Gebruik bij het invoegen in de DB ook mysql_real_escape_string
En je foutafhandeling in je query is met vakantie.
@Rik
Ja dat wist ik, alleen let ik daar niet steeds op als je snel iets wil testen typ je het snel en test je het uit. Werkt het dan snel weer verder gaan. En jij werkt met Adobe Dreamweaver toch? Werkt dat veel fijner dan NotePad ++.
@Maarten, ohja dat klopt. Zal ik toevoegen. Heb je ook even een PM gestuurd
@Aarclay, slordigheids foutje
Ja dat wist ik, alleen let ik daar niet steeds op als je snel iets wil testen typ je het snel en test je het uit. Werkt het dan snel weer verder gaan. En jij werkt met Adobe Dreamweaver toch? Werkt dat veel fijner dan NotePad ++.
@Maarten, ohja dat klopt. Zal ik toevoegen. Heb je ook even een PM gestuurd
@Aarclay, slordigheids foutje

Ik werk met Adobe Dreamweaver CS5 ja. Is niet ideaal voor PHP maar het doet wat het moet doen en ik heb geen zin om een andere PHP IDE (bijvoorbeeld PHPed) te downloaden.
En zelfs al test ik iets snel, dan nog let ik op indenting. Het is gewoon iets dat je automatisch gaat doen als je langer aan het programmeren bent.
En zelfs al test ik iets snel, dan nog let ik op indenting. Het is gewoon iets dat je automatisch gaat doen als je langer aan het programmeren bent.
Rik schreef:Oké, ik heb nu Notepad# van Maarten, en het werkt wel goed. Het doet precies wat je zei met:Ik werk met Adobe Dreamweaver CS5 ja. Is niet ideaal voor PHP maar het doet wat het moet doen en ik heb geen zin om een andere PHP IDE (bijvoorbeeld PHPed) te downloaden.
En zelfs al test ik iets snel, dan nog let ik op indenting. Het is gewoon iets dat je automatisch gaat doen als je langer aan het programmeren bent.
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]( ... ) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]iets[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]( ... ) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]iets 2[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]oh hallo[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]hallo 2[/COLOR][COLOR= #007700];[/COLOR]
?> Maartenl schreef:Wat is die plug-in als ik vragen mag?Er bestaat daar ook een plugin voor in notepad++
Gebruik bij het invoegen in de DB ook mysql_real_escape_string
Wel nice
Ik heb hem gedownload 
Ik heb hem gedownload 
Gamedealer schreef:Indent by flodGebruik bij het invoegen in de DB ook mysql_real_escape_stringEerdere citaten tonen
Maartenl schreef:Er bestaat daar ook een plugin voor in notepad++
Wat is die plug-in als ik vragen mag?
Voor als je een andere editor wilt PHPDesigner Hij kan elke script taal
Zullen we nu wel weer ontopic gaan 

Leuk man, 1 of andere kleuter heeft een porno plaatje in V2 ge-upload.
Altijd weer die kinderachtige mensen die zo iets leuks moeten verpesten.
Altijd weer die kinderachtige mensen die zo iets leuks moeten verpesten.
