3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** CONFIG */ $pageConf['title'] = ""; $pageConf['desc'] = ""; $pageConf['keywords'] = ""; /** PAGE SPECIFIC */ set_time_limit(600); /* FUNCTIONS */ function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } function imageThumbnail($inputFileName, $maxSize = 500) { $info = getimagesize($inputFileName); $type = isset($info['type']) ? $info['type'] : $info[2]; // Check support of file type if ( !(imagetypes() & $type) ) { // Server does not support file type return false; } $width = isset($info['width']) ? $info['width'] : $info[0]; $height = isset($info['height']) ? $info['height'] : $info[1]; // Calculate aspect ratio $wRatio = $maxSize / $width; $hRatio = $maxSize / $height; // Using imagecreatefromstring will automatically detect the file type $sourceImage = imagecreatefromstring(file_get_contents($inputFileName)); // Calculate a proportional width and height no larger than the max size. if ( ($width <= $maxSize) && ($height <= $maxSize) ) { // Input is smaller than thumbnail, do nothing return $sourceImage; } elseif ( ($wRatio * $height) < $maxSize ) { // Image is horizontal $tHeight = ceil($wRatio * $height); $tWidth = $maxSize; } else { // Image is vertical $tWidth = ceil($hRatio * $width); $tHeight = $maxSize; } $thumb = imagecreatetruecolor($tWidth, $tHeight); if ( $sourceImage === false ) { // Could not load image return false; } // Copy resampled makes a smooth thumbnail imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $tWidth, $tHeight, $width, $height); imagedestroy($sourceImage); return $thumb; } function imageToFile($im, $fileName, $quality = 80) { if ( !$im || file_exists($fileName) ) { return false; } $ext = strtolower(substr($fileName, strrpos($fileName, '.'))); switch ( $ext ) { case '.gif': imagegif($im, $fileName); break; case '.jpg': case '.jpeg': imagejpeg($im, $fileName, $quality); break; case '.png': imagepng($im, $fileName); break; default: return false; } return true; } /* UPLOAD */ if(isset($_POST['Submit'])) { $done = 0; for ($i = 0; $i < count($_FILES['file']['name']); $i++) { // stop if 10 files successfully done already if ($done => 10) { echo 'Limit of 10 files at one time reached.'; break; } // read name of file submitted for uploading $file = $_FILES['file']['name'][$i]; // check if (!$image) { continue; } // determine type of file $extension = strtolower(getExtension(stripslashes($_FILES['file']['name'][$i]))); if (($extension == 'jpg') || ($extension == 'jpeg') || ($extension == 'bmp') || ($extension == 'png') || ($extension == 'gif')) { // check filesize if (filesize($_FILES['image']['tmp_name'][$i]) > 10240*1024) { $error = 1; } // check mimetype $fileinfo = getimagesize($_FILES['image']['tmp_name'][$i]); if ($fileinfo['mime'] != 'image/gif' && $fileinfo['mime'] != 'image/jpeg' && $fileinfo['mime'] != 'image/png' && $fileinfo['mime'] != 'image/pjpeg' && isset($fileinfo)) { $error = 1; } // set file type $fileType = 'image'; } else if (($extension == 'mpg') || ($extension == 'mov') || ($extension == 'flv') || ($extension == 'mp4') || ($extension == 'wmv') || ($extension == 'webm') || ($extension == 'mkv') || ($extension == 'ogg')) { // check filesize if (filesize($_FILES['image']['tmp_name'][$i]) > 10240*1024) { $error = 1; } // check mimetype $fileinfo = getimagesize($_FILES['image']['tmp_name'][$i]); if ($fileinfo['mime'] != 'video/mpeg' && $fileinfo['mime'] != 'video/mp4' && $fileinfo['mime'] != 'video/ogg' && $fileinfo['mime'] != 'video/x-ms-wmv' && $fileinfo['mime'] != 'video/webm' && $fileinfo['mime'] != 'video/quicktime' && $fileinfo['mime'] != 'video/x-flv' && $fileinfo['mime'] != 'video/x-matroska' && isset($fileinfo)) { $error = 1; } // set file type $fileType = 'video'; } else { $error = 1; } // upload file to correct directory if empty($error) { $done++; // set paths // set folder path $datepath = date('mY'); $file_path = $_SERVER['DOCUMENT_ROOT'] . '/files/' . $datepath . '/'; $file_thumb_path = $_SERVER['DOCUMENT_ROOT'] . '/files/thumbs/' . $datepath . '/'; // upload to permanent location $file_id = randId(8,0,1); copy($_FILES['image']['tmp_name'][$i], $file_path . $file_id . $extension); // database // $file_id becomes file identifier // associate $file_id with user account // store $filetype // generate thumbnail // image if ($filetype == 'image') { $thumbgen = imageThumbnail($file_path . $file_id . $extension, 150); imagetofile($thumbgen, $file_thumb_path . $file_id . $extension); imagedestroy($thumbgen); } // video if ($filetype == 'video') { // actual size thumbnail (i.e. 640x480) //$file_thumb_path . $file_id . $extension // small thumbnail (150) //$file_thumb_path . $file_id . '-small' . $extension // video strip //$file_thumb_path . $file_id . '-strip' . $extension } } } } else { ?> <form style="margin-left:auto;margin-right:auto;" method="post" enctype="multipart/form-data" action=""> <input type="hidden" name="MAX_FILE_SIZE" value="10485760"> <input type="hidden" name="_mode" value="normal"> <div id="upload_fields"> <input name="file[]" type="file" size="30" alt="file select" multiple> <br><p class="index_intro" style="font-size:10.5px">If your browser only lets you select one file at a time please use the <a href="classic.php" rel="nofollow">classic uploader</a>.</p> </div> <div id="uploading" style="visibility:hidden;height:0px;"><img src="/_assets/images/upload_progress1.gif" alt="Uploading"></div> <input name="Submit" type="submit" id="submit" value="." style="color:#c1c6e1" onclick="uploadprogress('uploading');"> </form> <?php } ?>
Output for 5.4.0 - 5.4.24
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/6KGuD on line 119
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /in/6KGuD on line 119
Process exited with code 255.