Kleine Vragen Topic #2

Gestart doorKingunit3.067 reacties11.764 weergaven

3.068 berichten · pagina 41 van 205

Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Mijn script transleert de bestandsnamen in cijfers en letters graag wil de originele naam behouden. Ik weet dat het in dit stukje moet:

if($_SERVER[REQUEST_METHOD] == "POST") {
        $fname = $_FILES[filen][name];
        $fext = strtolower(end(explode(., $fname)));
        $ftemp = $_FILES[filen][tmp_name]; 
        $newname = md5(rand(rand(1, 9999), rand(1, 9999))) . "." . $fext; 
        $target = $tfolder . $newname; 

if(!empty($fname)) {
            // De extensie controleren
            foreach($extensions as $check) {
                if($check == $fext) {
                    $extensioncheck = true;


Maar ik zou bijgod niet weten waar omdat ik maar een noob ben in PHP etc. Heb ookal gezocht op google, maar kon niets vinden. (misschien op de verkeerde namen gezocht)

Graag hulp

toevoeging op 20 mei 2013, 171942:
Een link van google met daarin het antwoord is natuurlijk ook toegestaan

toevoeging op 20 mei 2013, 171948:
Een link van google met daarin het antwoord is natuurlijk ook toegestaan
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zal even zeggen wat dat script doet:
Regel 1: check of hij een POST request stuurt
Regel 2: hij zet de originele naam in $fname
Regel 3: hij zet de extensie van het bestand in $fext
Regel 4: hij haalt de locatie van het tijdelijke bestand op (waar hij dus geüpload is) en zet die in $ftemp
Regel 5: hij verzint een nieuwe bestandsnaam en zet die in $newname
Regel 6: hij zet de locatie waar het bestand straks komt in $target

Verder lukt het zelf denk ik wel?
0
Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Weet je dat zeker?

if($_SERVER[REQUEST_METHOD] == "POST") {
        $ftemp = $_FILES[filen][tmp_name];        
        $target = $tfolder ;


Kan dit kloppen of ben ik nu heel dom aan t denken?
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$target = $tfolder . $fname;
0
Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
En dan moet hij dus werken?
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Epicrobzer schreef:
En dan moet hij dus werken?
Nee, ik zie dat je $fname net weg hebt gehaald..

Dat stukje dat je plaatste moet dit worden:

if($_SERVER[REQUEST_METHOD] == "POST") {
        $fname = $_FILES[filen][name];
        $fext = strtolower(end(explode(., $fname)));
        $ftemp = $_FILES[filen][tmp_name]; 
        $target = $tfolder . $fname; 

if(!empty($fname)) {
            // De extensie controleren
            foreach($extensions as $check) {
                if($check == $fext) {
                    $extensioncheck = true;
$ftemp en $target zal hij verder in de code wel nodig hebben om het bestand te verplaatsen van $fname naar $target.

$newname = md5(rand(rand(1, 9999), rand(1, 9999))) . "." . $fext;
Heb je niet meer nodig, omdat je het bestand geen nieuwe naam wilt geven,
$target = $tfolder . $newname; moet $target = $tfolder . $fname; worden, omdat je het bestand op die originele naam wilt ipv die nieuwe naam.
0
Berichten
4.036
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt, nu snap ik het. Ook bedankt voor de uitleg erbij natuurlijk wink
toevoeging op 20 mei 2013, 17:57:38:
Maar $fext moet wel nog blijven toch?
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
OPGELOST, ZIE HIER

Hey,

Ik heb een probleempje met mijn bestand-share systeem. Ik kan 5 verschillende bestanden uploaden:

- mp3
- wav
- doc
- docx
- pdf

Bij de Word document gaat het fout. Bestanden worden opgeslagen buiten de public_html met timestamp-random code.ext.

Dit is het download scriptje:

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Pragma: public"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Cache-Control: must-revalidate, post-check=0, pre-check=0"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]mp3[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: audio/mpeg"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]wav[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: audio/x-wav"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]doc[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/msword"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]docx[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]pdf[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/pdf"[/COLOR][COLOR= #007700]);[/COLOR]
            
        [COLOR= #0000BB]$fileRoot[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]public_html[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]DOCUMENT_ROOT[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]fileUpload/[/COLOR][COLOR= #007700];[/COLOR]
            
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Length: "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fSize[/COLOR][COLOR= #007700]]);[/COLOR] 
            
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Content-Disposition: attachment; filename="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fOriginalName[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Transfer-Encoding: binary"[/COLOR][COLOR= #007700]);[/COLOR]

        [URL="http://www.php.net/readfile"]readfile[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileRoot[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fTimestamp[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000].[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]]);[/COLOR]

?>


$fFetch e.d. kloppen gewoon.

Als ik met deze een .doc bestand probeer te downloaden en die probeer te openen, krijg ik:
Afbeelding
Afbeelding

Als ik met deze code een .docx probeer te downloaden, krijg ik dit:
Afbeelding
Afbeelding

Maar daarna werkt hij wel normaal:
Afbeelding

Weet iemand hoe ik dit kan oplossen? De andere bestanden werken wel..

En de content-length werkt niet, Opera geeft elke keer andere grootte en in downloads is de grootte onbekend.

toevoeging op 20 mei 2013, 19:47:17:
En wav werkt helaas ook niet
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waar zie jij whitespace? Spaties en enters binnen PHP worden niet naar de client gestuurd hé.
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zoek 1 gemakkelijk code/site hoe ik een afbeelding laat sliden om de tijd.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Sanderc schreef:
Ik zoek 1 gemakkelijk code/site hoe ik een afbeelding laat sliden om de tijd.
Dat is geen vraag.
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Opgelost:

[COLOR= #0000BB]<?php

$fFetch[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$mysql[/COLOR][COLOR= #007700]->[/COLOR]fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$fQuery[/COLOR][COLOR= #007700]);[/COLOR]
                    
        [COLOR= #0000BB]$fileRoot[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]public_html[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]DOCUMENT_ROOT[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]fileUpload/[/COLOR][COLOR= #007700];[/COLOR]
        
        [COLOR= #0000BB]$fileContent[/COLOR] [COLOR= #007700]= @[/COLOR][URL="http://www.php.net/fopen"]fopen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileRoot[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fTimestamp[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000].[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #DD0000]rb[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Status: 200"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Pragma: public"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Cache-Control: must-revalidate, post-check=0, pre-check=0"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]mp3[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: audio/mpeg"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]wav[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: audio/wav"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]doc[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/vnd.ms-word; charset=Windows-1252"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]docx[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=Windows-1252"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/else"]else[/URL] [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]pdf[/COLOR][COLOR= #007700])[/COLOR]
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Type: application/pdf"[/COLOR][COLOR= #007700]);[/COLOR]
            
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Content-Disposition: attachment; filename="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fOriginalName[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Transfer-Encoding: binary"[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-Length: "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fSize[/COLOR][COLOR= #007700]]);[/COLOR] 
        
        [URL="http://www.php.net/ob_clean"]ob_clean[/URL][COLOR= #007700]();[/COLOR] 
        [URL="http://www.php.net/flush"]flush[/URL][COLOR= #007700]();[/COLOR]

        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileContent[/COLOR][COLOR= #007700])
        {[/COLOR]
            
            [URL="http://www.php.net/while"]while[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/feof"]feof[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileContent[/COLOR][COLOR= #007700])) {[/COLOR]
                
                [URL="http://www.php.net/print"]print[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/fread"]fread[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileContent[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/filesize"]filesize[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileRoot[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fTimestamp[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000].[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$fFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]fExt[/COLOR][COLOR= #007700]])));[/COLOR]
                
                [URL="http://www.php.net/flush"]flush[/URL][COLOR= #007700]();[/COLOR]
                
                [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/connection_status"]connection_status[/URL][COLOR= #007700]()!=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]) 
                {
                    
                    @[/COLOR][URL="http://www.php.net/fclose"]fclose[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fileContent[/COLOR][COLOR= #007700]);[/COLOR]
                    [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]();
                    
                }
                
            }
            
        }[/COLOR]

?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Ik raad je wel aan om met een switch te werken i.p.v. zoveel elseif-jes
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren