Nogen som er strappe til at lege i php?.
Skal have lavet et script lidt om, så den kan uploade billederne i to versioner.
1: Et lille i max 50x50px.
2: Et større i eventuelt original størrelse eller 300x300px.
Hvis muligt, så gerne et watermark.png på det større billed.
Kodescript:
- <div class="wrap">
- <?php
- $billeder = "autrailien_billeder";
- $getCount = mysql_fetch_object(mysql_query("SELECT COUNT(*) AS `count` FROM `".$billeder."` WHERE `status` = '0'"));
- if($getCount -> count > 0) :
- echo ("<span style='float:right;margin-right:35px;padding:4px;font-family:Lucida Console, Monaco, monospace;border:1px solid #000;border-radius:5px;'><a href='?blog=funkt/udfyld'>".$getCount -> count." billeder ikke færdige !</a></span>");
- else:
- echo ("<span style='float:right;margin-right:35px;padding:4px;font-family:Lucida Console, Monaco, monospace;border:1px solid #000;border-radius:5px;'>Alle billeder er færdige.</span>");
- endif;
- $codelenght = 30;
- while(strlen($billed) < $codelenght) {
- $part = rand(1,3);
- if($part==1){$a=48;$b=57;}
- if($part==2){$a=65;$b=90;}
- if($part==3){$a=97;$b=122;}
- $billed .= chr(rand($a,$b));
- }
- $valid_formats = array("jpeg", "jpg", "png", "gif");
- $max_file_size = 2048*1000;
- $path = "billeder/". $billed ."_"; // Upload directory
- $count = 0;
- $beskrivelse = htmlspecialchars($_POST['beskrivelse']);
- if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
- // Loop $_FILES to execute all files
- foreach ($_FILES['files']['name'] as $f => $name) {
- if ($_FILES['files']['error'][$f] == 4) {
- continue; // Skip file if any error found
- }
- if ($_FILES['files']['error'][$f] == 0) {
- if ($_FILES['files']['size'][$f] > $max_file_size) {
- $message[] = "$name is too large!.";
- continue; // Skip large files
- }
- elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
- $message[] = "$name is not a valid format";
- continue; // Skip invalid file formats
- }
- else{ // No error found! Move uploaded files
- if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) {
- $count++; // Number of successfully uploaded files
- $codelenght = 30;
- while(strlen($billed) < $codelenght) {
- $part = rand(1,3);
- if($part==1){$a=48;$b=57;}
- if($part==2){$a=65;$b=90;}
- if($part==3){$a=97;$b=122;}
- $billed .= chr(rand($a,$b));
- }
- mysql_query("INSERT INTO `autrailien_billeder` (`FILE_NAME`) VALUES ('". $billed ."_". $name ."')");
- echo ("<meta HTTP-EQUIV='REFRESH' CONTENT='5; URL=?blog=funkt/udfyld'>");
- }
- }
- }
- }
- }
- if (isset($message)) {
- foreach ($message as $msg) {
- printf("<p class='status'>%s</p></ br>\n", $msg);
- }
- }
- if($count !=0){
- printf("<p class='status'>%d billeder blev uploaded.<br />Du bliver sendt videre til beskrivelse til dit/dine billeder.</p>\n", $count);
- }
- ?>
- <p>Max site på 2 MB - Tilladte typer: jpg, png, gif</p>
- <br />
- <br />
- <form action="" method="post" enctype="multipart/form-data">
- <input type="file" name="files[]" multiple="multiple" accept="image/*">
- <input type="submit" value="Upload">
- </form>
- </div>
Indlæg senest redigeret d. 24.11.2013 01:49 af Bruger #17554