皆さん、私は指定されたディレクトリに画像をアップロードしようとしていますが、出力として取得するすべての画像は「ファイルをアップロードする際にエラーが発生しました。もう一度やり直してください!イメージのアップロードエラー
$upload_dir = "blog/wp-content/uploads/products";
if (file_exists($upload_dir) && is_writable($upload_dir)) {
echo "Directory exists and is fine....";
}
else {
echo "Upload directory is not writable, or does not exist.";
}
$target_path = "blog/wp-content/uploads/products/";
$target_path = $target_path . basename($_FILES['image_file']['name']);
if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['image_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
また、アップロード状況を '$ _FILES ['image_file'] ['error']' [(php.net docs)](http://php.net/manual/en/features.file- upload.errors.php)このエラーコードは、失敗の原因を示している可能性があります。 – mkilmanas
本当に元のファイル名を保持しないでください。誰かがPHPファイルをアップロードすると想像してください、あなたのウェブサーバは喜んでそれを実行します。 – Maerlyn
'$ target_path'は書き込み可能ですか? –