Example #1
0
function isImageByExt($filename)
{
    $ext = strtolower(getfileExt($filename));
    $types = "gif|jpg|jpeg|png|bmp";
    if ($ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'bmp') {
        return true;
    }
    return false;
}
Example #2
0
function postfit()
{
    //get file extension first. Compatible with php4 and above
    $filext = getfileExt($_FILES['fitfile']['name']);
    //only continue id file extension is .fit or .tcx (case insensitive)
    if ($filext == "fit" || $filext == "tcx") {
        //save the uploaded file with the date attached to the name
        $newfilename = "uploads/" . date("Y-m-d") . "_" . $_FILES['fitfile']['name'];
        move_uploaded_file($_FILES['fitfile']['tmp_name'], $newfilename);
        //read data from the file
        $handle = fopen($newfilename, 'r');
        $data = fread($handle, filesize($newfilename));
        fclose($handle);
        //do a curl call with post data
        $url = "http://www.strava.com/api/v2/upload";
        $fields = array('token' => urlencode($_SESSION['token']), 'id' => urlencode($_SESSION['id']), 'data' => urlencode($data), 'type' => urlencode($filext));
        $fields_string = '';
        foreach ($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        rtrim($fields_string, '&');
        $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields_string);
        $ch = curl_init($url);
        curl_setopt_array($ch, $options);
        $content = curl_exec($ch);
        $err = curl_errno($ch);
        $errmsg = curl_error($ch);
        $header = curl_getinfo($ch);
        curl_close($ch);
        $data = json_decode($content);
        //print_r($data);
        if (isset($data->upload_id)) {
            return $data->upload_id;
        } else {
            return "Upload Error";
        }
    } else {
        return "File Error";
    }
}
Example #3
0
<?php

header('content-type: text/html; charset=utf-8');
require "./include/init.php";
require_once './include/file.func.tool.php';
$file = $_FILES['upload'];
/*print_r($file);
exit;
*/
if ($file['error'] != 0) {
    echo "文件上传失败!";
    exit;
}
$filedir = './data/uploadfile/';
$path = mk_dir($filedir) . '/' . randName() . '.' . getfileExt($file['name']);
/*print_r($path);
exit;
*/
if (move_uploaded_file($file['tmp_name'], $path)) {
    $msg = "success";
} else {
    echo "文件上传失败,请稍后再试";
    exit;
}
$username = trim($_POST['username']);
// session 隐式传入
$filename = $file['name'];
$filepath = $path;
$uptime = time() + 8 * 3600;
$sql = "insert into files (username, filename, filepath, uptime)" . "values ('{$username}', '{$filename}', '{$filepath}', '{$uptime}')";
if (!mysql_query($sql, $conn)) {