Upload script probleem.

  • Dus, ik wil eigenlijk dit...


    Dat ie de filename, Auto renamed naar song**.mp3


    Die ''**'' Moeten in cijfers veranderen.


    Dus bevoorbeeld,


    ik upload hoi.mp3 op.


    Die wordt gerenamed naar song1.mp3


    Iemand anders load qskdklq.mp3 op.


    Dan wordt die gerenamed naar song2.mp3



    Ik zou het waarderen, als iemand mij hierbij zou helpen.




  • Guest, wil je besparen op je domeinnamen? (ad)
  • Als aller eerste, wat overzicht in je programming zou geen probleem zijn voor het het debuggen ervan aangezien dat nu best irritant is om te doen, daarnaast als je een rename wilt uitvoeren in je upload script, waarom doe je dat dan niet? Aangezien ik zelf die niet terug kan vinden.


    Voor de rest is het script goed te doen hier en daar een wel wat omslachtige manier om er voor te zorgen dat hij iets controleert, maar er zijn altijd makkelijkere manieren zelfs voor iemand die al 10 jaar programmeert.


    Kijk eens naar deze (Dit script is niet getest):
    http://pastebin.com/JsZGHsL1


    Hiermee kan je is nagaan wat je miste, let voornamelijk op de error afhandeling en de renaming van je files naar song*.mp3 aangezien je die er niet in had zitten ga ik er vanuit dat je daar tegen aanliep om het werkend te krijgen, voel vrij om meer informatie er over te vragen als je iets niet snapt. :)

  • Bedankt, dit is wat ik er van heb kunnen maken.
    [PHP]
    <?php
    // Simple PHP Upload Script: http://coursesweb.net/php-mysql/


    $uploadpath = ''; // directory to store the uploaded files
    $max_size = 200000000; // maximum file size, in KiloBytes
    $alwidth = 90000; // maximum allowed width, in pixels
    $alheight = 80000; // maximum allowed height, in pixels
    $allowtype = array('mp3'); // allowed extensions
    $newfilename = 'song' . ($fileCount + 50) . '.mp3'; //New File Name


    if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
    $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
    $sepext = explode('.', strtolower($_FILES['fileup']['name']));
    $type = end($sepext); // gets extension
    list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
    $err = ''; // to store the errors


    // Checks if the file has allowed type, size, width and height (for images)
    if(!in_array($type, $allowtype)) $err .= 'Upload Failed, Invalid Extension';
    if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
    if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;


    // If no errors, upload the image, else, output the errors
    if($err == '') {
    if(move_uploaded_file($_FILES["fileup"]["tmp_name"], "" . $newfilename)) {
    echo 'Song successfully uploaded';
    echo '<br />Link To Song <input type="text" class="optionstxt" readonly style="width:300px;" value="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'">';



    }
    else echo '<b>Unable to upload the file.</b>';
    }
    else echo $err;
    }
    ?> [/code]


    Het probleem? Hij renamed naar Song**.mp3
    Het probleem is, dat ie steeds dezelfde cijfer pakt.
    Dus niet van 1 naar 2 etc gaat.

  • ik heb er ondertussen dit van gemaakt.
    Bedankt voor alle hulp!
    Alleen vroeg ik mij af, als het mogelijk is. een Lijst te hebben met alle .mp3 files.



    [PHP]<?php
    // Simple PHP Upload Script: http://coursesweb.net/php-mysql/


    $uploadpath = ''; // directory to store the uploaded files
    $max_size = 200000000; // maximum file size, in KiloBytes
    $alwidth = 90000; // maximum allowed width, in pixels
    $alheight = 80000; // maximum allowed height, in pixels
    $allowtype = array('mp3'); // allowed extensions
    $fileCount = (int) count(glob($uploadpath . "*.mp3"));
    $newfilename = 'song' . ($fileCount + 1) . '.mp3'; //New File Name



    if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
    $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
    $sepext = explode('.', strtolower($_FILES['fileup']['name']));
    $type = end($sepext); // gets extension
    list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
    $err = ''; // to store the errors


    // Checks if the file has allowed type, size, width and height (for images)
    if(!in_array($type, $allowtype)) $err .= 'Upload Failed, Invalid Extension';
    if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
    if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;


    // If no errors, upload the image, else, output the errors
    if($err == '') {
    if(move_uploaded_file($_FILES["fileup"]["tmp_name"], "" . $newfilename)) {
    echo 'Song successfully uploaded';
    echo '<br />Link To Song <input type="text" class="optionstxt" readonly style="width:300px;" value="http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$newfilename.'">';



    }
    else echo '<b>Unable to upload the file.</b>';
    }
    else echo $err;
    }
    ?> [/PHP]

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!