我有一个PHP脚本,它发布到Mixcloud,并收到一个我无法解决的错误。
这是使用PHP 7.3.6和curl,正如我在其他帖子中看到的示例。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.mixcloud.com/upload/?access_token=$mixcloud");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60 * 10);
curl_setopt($ch, CURLOPT_NOPROGRESS, true);
$server_output = curl_exec($ch);
curl_close ($ch);
// load json response into array
$res = json_decode($server_output, true);
echo print_r( $post, true );
echo print_r($res, true);上传失败,并发送了以下帖子:
Array
(
[mp3] => @/var/share_ro/fullshow/surface.mp3
[name] => Upload title
[description] => Upload description
[picture] => @/var/share_ro/fullshow/avatar.png
[tags-0-tag] => Tag1
[tags-1-tag] => Tag2
[tags-2-tag] => Tag3
[tags-3-tag] => Tag4
[tags-4-tag] => Tag5
)和响应:
Array
(
[details] => Array
(
[mp3] => Array
(
[0] => This field is required.
)
)
[error] => Array
(
[message] =>
[type] => PostValidationError
)
)但是,文件的完整路径确实存在,我尝试了在文件名中使用和不使用前导@:
$ ls -lah /var/share_ro/fullshow/surface.mp3
-rw-r--r-- 1 user mp3 79M Jun 11 16:08 /var/share_ro/fullshow/surface.mp3有没有人知道我做错了什么?
发布于 2019-12-08 03:31:48
我最终在shell脚本中使用了curl,运行良好:
$script = "/home/user/code/scripts/mixcloud.sh";
$server_output = shell_exec("$script $mixcloud $mp3 '$name' '$host' '$title' '$desc' '$picfile' $tag1 $tag2");脚本是:
#!/bin/bash
# Script to upload file to Mixcloud - see send_to_mixcloud function in make_fullshow.php
TOKEN=$1
MP3=$2
NAME=$3
ARTIST=$4
ALBUM=$5
DESC=$6
PIC=$7
TAG1=$8
TAG2=$9
TAG3=${10}
TAG4=${11}
TAG5=${12}
curl -F "mp3=@$MP3" \
-F "name=$NAME" \
-F "picture=@$PIC" \
-F "description=$DESC" \
-F "tags-0-tag=$TAG1" \
-F "tags-1-tag=$TAG2" \
-F "tags-2-tag=$TAG3" \
-F "tags-3-tag=$TAG4" \
-F "tags-4-tag=$TAG5" \
https://api.mixcloud.com//upload/?access_token=$TOKEN发布于 2020-04-17 13:18:09
我回来尝试使用几年前找到的this script,但它不再对我起作用,并显示与您完全相同的错误消息。你的回答对我帮助很大,但我想我应该把这个“简化”贴到你正在为我工作的工作中。执行完全相同的操作,只是不需要外部shell脚本文件。
$script = 'curl';
foreach ($post as $key => $value) {
$script .= " -F \"$key=$value\"";
}
$script .= " https://api.mixcloud.com/upload/?access_token={$token}";
$server_output = shell_exec($script);https://stackoverflow.com/questions/56551232
复制相似问题