私は uploadify を使用して画像をサーバーにアップロードし、そのファイル名をデータベースにアップロードしてから、wordpress を使用してこれらの写真を使用するページを動的に生成しています。これまでのところ、私が持っているものは時々うまくいきますが、うまくいかないこともあります。
ファイル名が既に存在するかどうかを確認するためにuploadifyが必要です(数百人の異なるユーザーが画像をアップロードしています)。ファイル名が一致する場合、uploadifyはユーザーにファイルの名前を変更するように求めるエラーを返します ファイルが正常にアップロードされたら。アップロードボタンを削除し、ファイルの名前を隠しフィールドに戻し、データベースに送信します。
次に、データベースから取得したこのファイル名を使用して、ファイルを探す場所を WP に伝えます。
ただし、作成されたページでファイルが正常に表示されることがありますが、戻ってきて、ファイルへのアクセスが禁止されていることが示されることがあります。私は読み上げて、uploadify の許可の問題のいくつかのケースを見つけましたが、私が見つけて試したものは何も成功しませんでした。chmod コマンドを uploadify.php に追加しようとしましたが、うまくいきませんでした。サーバー上のフォルダーのアクセス許可を変更しようとしましたが、今後アップロードされるファイルには何もしませんでした。問題を解決するためにどこから始めればよいかさえ、何が問題なのかわかりません。以下は、私の HTML (完全な HTML ページは非常に大きいため、関連する uploadify コンテンツを含む抜粋のみ) と、uploadify.php ファイル (それぞれに異なるパラメーター チェックがあるため 2 つある.
ヘッダーからスクリプトをアップロードします (両方):
$(function() {
$('#photo_upload').uploadify({
'buttonText' : 'Select File',
'multi' : false,
'method' : 'post',
'fileSizeLimit' : '100KB',
'height' : 20,
'swf' : 'uploadify-v3/uploadify.swf',
'uploader' : 'uploadify-v3/uploadify.php',
'onUploadStart' : function(file) {
$('#photo_upload').uploadify('settings','formData',{'upName' : $('#usersName').val()});
},
'onUploadSuccess' : function(file, data) {
if(data == 'failed'){
alert('The file you attempted to upload failed. Please check that the file meets all requirements, then try again. Thank you.');
} else if(data == 'FileNameExists'){
alert('An image with the same file name already exists. Please rename the file to a different name, then try again. Thank you.');
} else{
$("#photo_upload").remove();
var starting = data.indexOf("upload-images");
var savedAs = data.substring(starting+14 , data.indexOf(".jpg"))+".jpg";
document.form.photo.value = savedAs;
}
}
// Your options here
});
$('#logo_upload').uploadify({
'buttonText' : 'Select File',
'multi' : false,
'method' : 'post',
'fileSizeLimit' : '100KB',
'height' : 20,
'swf' : 'uploadify-v3/uploadify.swf',
'uploader' : 'uploadify-v3/uploadify2.php',
'onUploadStart' : function(file) {
$('#logo_upload').uploadify('settings','formData',{'upName' : $('#usersName').val()});
},
'onUploadSuccess' : function(file, data) {
if(data == 'failed'){
alert('The file you attempted to upload failed. Please check that the file meets all requirements, then try again. Thank you.');
} else if(data == 'FileNameExists'){
alert('An image with the same file name already exists. Please rename the file to a different name, then try again. Thank you.');
} else{
$("#logo_upload").remove();
var starting = data.indexOf("upload-images");
var savedAs = data.substring(starting+14 , data.indexOf(".jpg"))+".jpg";
document.form.logo.value = savedAs;
}
}
// Your options here
});
});
HTML (これは、アップロードのボタンとフィールドに関連する HTML です):
<span class="Form-Header">Upload Images</span>
<br />
<div id="Form-wrapper">
<div id="Form-wrapper-left">
Your Photograph:<br />
</div>
<div id="Form-wrapper-right">
<input name="photo" type="hidden" id="photo" value="NULL"/>
<input type="file" name="photo_upload" id="photo_upload" />
(Image Dimensions: 300w x 420h, JPEG) (100kb Size Limit)
</div>
<div id="clear" style="clear:both;"></div>
<br />
</div>
<div id="Form-wrapper">
<div id="Form-wrapper-left">
Your Logo:<br />
</div>
<div id="Form-wrapper-right">
<input name="logo" type="hidden" id="logo" value="NULL"/>
<input type="file" name="logo_upload" id="logo_upload" />
(Image Dimensions: 450w x 65h, JPEG) (100kb Size Limit)
</div>
<div id="clear" style="clear:both;"></div>
</div>
<div id="Form-wrapper">
<div id="Form-Footer"><strong>Next: </strong> Go <a href="#top">to the top of the page</a> and click on "Profile Information" to continue.<br />
</div>
<div id="clear" style="clear:both;"></div>
</div>
最後に、uploadify1 と uploadify2 の PHP ページを次に示します (サイズ要件を除いてどちらも同じであるため、1 つだけを表示しています)。
<?php
// Define a destination
$targetFolder = '/Eye-Doctors/upload-images'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$size = getimagesize($tempFile);
if($size[0] <= 300 && $size[1] <= 420){
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
$exists = 0;
if( file_exists($targetFile) ) {
$exists = 1;
echo 'FileNameExists';
}
if($exists == 0){
move_uploaded_file($tempFile,$targetFile);
echo $targetFile;
}
} else {
echo 'failed';
}
} else{
echo 'failed';
}
}
?>
これが助けを得るのに十分な情報であることを本当に願っています. どこでも解決策を探してみましたが、まだ見つかりません。他にご不明な点がございましたら、お気軽にお問い合わせください。