photo upload bei runs geht jetzt (beim ergebnis eintragen)
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
This commit is contained in:
@ -243,6 +243,68 @@ function pictshareUploadImage($path,$hash=false)
|
||||
return $json;
|
||||
}
|
||||
|
||||
// takes $_FILES['file'] as input and validates, throws error if fails, else returns URL of the image
|
||||
function pictShareFormValidateAndUpload($file,$key=false)
|
||||
{
|
||||
if($key===false)
|
||||
{
|
||||
$photo_name = $file['name'];
|
||||
$photo_tmp_name = $file['tmp_name'];
|
||||
$photo_size = $file['size'];
|
||||
$photo_error = $file['error'];
|
||||
$photo_type = $file['type'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$photo_name = $file['name'][$key];
|
||||
$photo_tmp_name = $file['tmp_name'][$key];
|
||||
$photo_size = $file['size'][$key];
|
||||
$photo_error = $file['error'][$key];
|
||||
$photo_type = $file['type'][$key];
|
||||
}
|
||||
|
||||
$allowed = ['jpg','jpeg','png','gif'];
|
||||
$photo_ext = strtolower(end(explode('.', $photo_name)));
|
||||
|
||||
if(in_array($photo_ext, $allowed))
|
||||
{
|
||||
if($photo_error === 0)
|
||||
{
|
||||
if($photo_size < 10000000)
|
||||
{
|
||||
$answer = pictshareUploadImage($photo_tmp_name);
|
||||
if($answer['status']=='ok' && in_array($answer['filetype'],['jpeg','png','gif']))
|
||||
return $answer['url'];
|
||||
else
|
||||
throw new Exception('Fehler beim CDN Upload: '.json_encode($answer,true));
|
||||
}
|
||||
else
|
||||
throw new Exception('Die Datei ist zu groß. Bitte eine kleinere Datei hochladen');
|
||||
}
|
||||
else
|
||||
throw new Exception('Fehler beim Upload: '.getFileUploadError($photo_error));
|
||||
}
|
||||
else
|
||||
throw new Exception('Dateityp nicht erlaubt. Bitte nur '.implode(', ',$allowed).' hochladen');
|
||||
|
||||
}
|
||||
|
||||
function getFileUploadError($error)
|
||||
{
|
||||
$phpFileUploadErrors = array(
|
||||
0 => 'There is no error, the file uploaded with success',
|
||||
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
|
||||
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
|
||||
3 => 'The uploaded file was only partially uploaded',
|
||||
4 => 'No file was uploaded',
|
||||
6 => 'Missing a temporary folder',
|
||||
7 => 'Failed to write file to disk.',
|
||||
8 => 'A PHP extension stopped the file upload.',
|
||||
);
|
||||
|
||||
return $phpFileUploadErrors[$error];
|
||||
}
|
||||
|
||||
function partial($name,$variables=[])
|
||||
{
|
||||
$templatefile = ROOT.DS.'templates'.DS.'partials'.DS.$name;
|
||||
|
Reference in New Issue
Block a user