Код: Выделить всё
//$entry[35] is the file upload field in the form.
//This grabs the uploaded file whatever it may be, and uploads it to the server
$newest_again = str_replace('[',"",$entry[35]);
$newest_final = str_replace(']',"",$newest_again);
$newest_fin = str_replace('"',"",$newest_final);
$entryArr = explode(",",$newest_fin);
if(!empty($entry[35])){
if(count($entryArr) > 1){
//multiple files have been added to the upload field
$count = 0;
$token = "";
$fileArr = array();
$binArr = array();
$extens = array();
foreach($entryArr as $file_entry){
//processing string to grab the file name only for each file
$new = str_replace('\\',"",$file_entry);
$new_again = str_replace('[',"",$new);
$new_final = str_replace(']',"",$new_again);
$new_fin = str_replace('"',"",$new_final);
$binFile = file_get_contents($new_fin);
$ext = pathinfo($new_fin, PATHINFO_EXTENSION);
array_push($fileArr, $new_fin);
array_push($binArr, $binFile);
array_push($extens, $ext);
}
//upload each file to server
while($count < (count($fileArr))){
$upload = curlUpload("/uploads.json", $binArr[$count], 'screenshot-'.$count.".".$extens[$count], $fileArr[$count],$token); // Attachments will have the prettyname screenshot.[$ext]
if($token == ""){
$token = $upload->upload->token;
}
else{
$token = $token;
}
$count ++;
}
print_r($uploads);
}
else{
//just one file was added to the form, so upload it
$fileArr = array();
$placeholder ="";
$new = str_replace('\\',"",$entry[35]);
$new_again = str_replace('[',"",$new);
$new_final = str_replace(']',"",$new_again);
$new_fin = str_replace('"',"",$new_final);
$binaryFile = file_get_contents($new_fin);
$ext = pathinfo($new_fin, PATHINFO_EXTENSION); // Upload field ID
$upload = curlUpload("/uploads.json", $binaryFile, 'screenshot.'.$ext, $new_fin, $placeholder); // Attachments will have the prettyname screenshot.[$ext]
$token = $upload->upload->token;
}
}
< /code>
Ошибка: < /p>
PHP Fatal error: Uncaught ValueError: Path cannot be empty in /wp-content/themes/blankslate/functions.php:31483
< /code>
стек: < /p>
#0 /wp-content/themes/blankslate/functions.php(31483): file_get_contents('')
< /code>
Эта ошибка выбрасывается только в том случае, если файл не добавляется в поле загрузки в форме. Если добавлен файл или файлы, ошибка не выбрасывается. Кажется, это вызов file_get_contents (); и бросить сообщение об ошибке, когда ничего не было добавлено в поле загрузки в форме. Это строка, которая бросает сообщение об ошибке: < /p>
$binFile = file_get_contents($new_fin);
< /code>
Я обернул все в этом блоке: < /p>
if(!empty($entry[35])){
Подробнее здесь: https://stackoverflow.com/questions/745 ... ty-on-php8