3
순수 jquery/Javascript 및 php5로 만든 여러 파일 업 로더가 필요합니다. 플래시 파일을 사용하지 마십시오. 시체에 코드가 있으면 나와 공유하십시오. 필자는 File API를 사용해 보았지만 IE와 Opera는 지원하지 않았습니다.순수 JQuery와 PHP5를 사용하는 여러 파일 업 로더?
순수 jquery/Javascript 및 php5로 만든 여러 파일 업 로더가 필요합니다. 플래시 파일을 사용하지 마십시오. 시체에 코드가 있으면 나와 공유하십시오. 필자는 File API를 사용해 보았지만 IE와 Opera는 지원하지 않았습니다.순수 JQuery와 PHP5를 사용하는 여러 파일 업 로더?
blueimp jQuery File Upload을 사용하면 클라이언트 측에서 여러 파일을 업로드 할 수 있습니다. 많은 옵션이 있으며, 사용자 정의 할 수 있습니다.
PHP 측에서 수행 할 작업에 대한 아이디어가있을 수 있습니다 (이미지 업로드 양식의 일부 스 니펫이므로 일부 변수는 $ log 또는 $ confImages와 같이 정의되지 않지만 아이디어를 얻을 수 있습니다).) :
//Сheck that we have a file
if (empty($uploaded_image))
return false;
if ($uploaded_image['error']) {
$log->LogError($uploaded_image['error'] . ": Error uploading file.");
return false;
}
list($dirname, $basename, $extension, $filename) = array_values(pathinfo($uploaded_image['name'])); //Extract variables: dirname, basename, extension, filename
//Normalize file name. I may suggest using http://cubiq.org/the-perfect-php-clean-url-generator than this
$filename = iconv("utf-8","ascii//TRANSLIT",$filename);
$allowedExt = array("jpg","jpeg","gif","png");
$extension = strtolower($extension);
//Check if the image has allowed type
if (empty($extension) || !in_array($extension, $allowedExt)) {
$log->LogError("invalid_extension: Not allowed to upload file ".(empty($extension) ? "without extension" : "with extension $extension").". Allowed Extensions: ". implode(",",$allowedExt));
return false;
}
//Generate some random string in case if such file exists on server
$postfix = substr(md5(uniqid(rand(),1)), 3, 5);
$newFile = $_SERVER['DOCUMENT_ROOT'].$upload_folder."/".$filename.'_'.$postfix.'.'.$extension; //new filename with appended random string to original filename);
//Check if the file with the same name is already exists on the server
if (file_exists($newFile)) {
$log->LogError("file_exists: File couldn't be uploaded, because such filename exist ".basename($newFile)." jau eksistē");
}
//Attempt to move the uploaded file to it's new place
if (move_uploaded_file($uploaded_image['tmp_name'],$newFile)) {
//I do some resizing also using http://phpthumb.gxdlabs.com/
$convertedimage = PhpThumbFactory::create($newFile, array("jpegQuality" => 80));
if (isset($confImages["max_width"]) || isset($confImages["max_height"]))
$convertedimage->resize($confImages["max_width"], $confImages["max_height"]);
$convertedimage->save($newFile);
//Save image path to database
...
return $image;
} else {
$log->LogError("Couldn't copy file from temp folder " . $uploaded_image['tmp_name'] . " to location " . $newFile);
}
return false;
안녕하세요. Janis Veinbergs님께 감사드립니다. :) – learner