[Просьба] Выдача ссылки после загрузки файла на сервер
Invision Power Board -> globalTemplate:
<script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('myf1_upload_process').style.visibility = 'visible'; document.getElementById('myf1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="mymsg">The file was uploaded successfully!<\/span>'; } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').style.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerHTML = result + '<br/>File: <input name="myfile" type="file" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style.visibility = 'visible'; return true; } //--> </script> upload.php <?php // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); $imagetypes = array( 'image/png' => '.png', 'image/gif' => '.gif', 'image/jpeg' => '.jpg', 'image/bmp' => '.bmp'); $ext = $imagetypes[$_FILES['myfile']['type']]; $randval = time(); $newname = $randval . $ext; if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $newname)) { $result = 1; } sleep(1); ?> <script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script> <form action="myuploader/upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" > <div style="margin-top:-40px"> <p id="myf1_upload_process"><strong>UpLoading...</strong> <br/> <img src="myuploader/loader.gif" /> <br/> </p> <p id="myf1_upload_form" align="left"> <br/> File: <input type="file" name="myfile" accept="image/*" size="0" /> <input type="submit" name="submitBtn" class="mysbtn" value="Upload" /> </p> </div> <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe> </form> editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); Как сделать так,чтобы после завершения загрузки ссылка на фото которую загрузили автоматически вставилос в editor editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); в тегах ![]() --------------------------------------------------------------------------------------- или ... <script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('myf1_upload_process').sty le.visibility = 'visible'; document.getElementById('myf1_upload_form').style. visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="mymsg">The file was uploaded successfully!<\/span>'; } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').sty le.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerH TML = result + '<br/>File: <input name="myfile" type="file" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style. visibility = 'visible'; return true; } //--> </script> подскажите как выводит вместо него, или в нем: result = '<span class="mymsg">The file was uploaded successfully!<\/span>'; это: (вы лучше знайте: хочу чтоб выводилось ссылка на загружаемого файла): echo "Адрес <a href=\"myuploader/$new_name\">http://my_site_url/myuploader/$newname</a>"; |
сделал вот так:
<script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('myf1_upload_process').style.visibility = 'visible'; document.getElementById('myf1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="mymsg">The file was uploaded successfully!<\/span>'; } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').style.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerHTML = result + '<br/>File: <input name="myfile" type="file" accept="image/*" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style.visibility = 'visible'; editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); editor.insert("[img]URL For Uploaded Photo[/img]", true ); return true; } //--> </script> добавил: editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); editor.insert("[img]URL For Uploaded Photo[/img]", true ); и он вставляет: [img]URL For Uploaded Photo[/img] но, как получить ссылку на фото вместо: URL For Uploaded Photo |
сделал вот так
<?php // Edit upload location here $destination_path = getcwd().DIRECTORY_SEPARATOR; $result = 0; $target_path = $destination_path . basename( $_FILES['myfile']['name']); $imagetypes = array( 'image/png' => '.png', 'image/gif' => '.gif', 'image/jpeg' => '.jpg', 'image/bmp' => '.bmp'); $ext = $imagetypes[$_FILES['myfile']['type']]; $randval = time(); $newname = $randval . $ext; if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $newname)) { echo "<script type='text/javascript'>alert('http://my_site.com/myupluader/$newname');</script>"; $fileurl = 'http://my_site.com/myupluader/$newname'; $result = 1; } sleep(1); ?> <script language="javascript" type="text/javascript">window.top.window.stopUpload('<?php echo $result; ?>', '<?php echo $fileurl; ?>');</script> <script language="javascript" type="text/javascript"> <!-- function startUpload(){ document.getElementById('myf1_upload_process').style.visibility = 'visible'; document.getElementById('myf1_upload_form').style.visibility = 'hidden'; return true; } function stopUpload(success){ var result = ''; if (success == 1){ result = '<span class="mymsg"><\/span>'; editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); editor.insert("[img]+$fileurl+[/img]", true ); } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').style.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerHTML = result + '<br/><input type="hidden" name="MAX_FILE_SIZE" value="5000000">File: <input name="myfile" type="file" accept="image/*" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style.visibility = 'visible'; return true; } //--> </script> echo заработал, и там ссылка выводится но никак не получается выводит ссылку в яваскрипт и вставлять его в редакторе: editor.insert("[img]+$fileurl+[/img]", true ); |
а с чего ты взял, что он поймет что такое $fileurl?
ты же тут пожал функции stopUpload 2 переменные - <script language="javascript" type="text/javascript"> window.top.window.stopUpload( '<?php echo $result; ?>', // 1-ая перем '<?php echo $fileurl; ?>' // 2-ая перем ); </script> вот и вытаскивай их тут function stopUpload(success, fileurl){ var result = ''; if (success == 1){ result = '<span class="mymsg"><\/span>'; editor = ipb.textEditor.getEditor(ipb.topic.fastReplyId); editor.insert("[img]"+fileurl+"[/img]", true ); } else { result = '<span class="myemsg">There was an error during file upload!<\/span>'; } document.getElementById('myf1_upload_process').style.visibility = 'hidden'; document.getElementById('myf1_upload_form').innerHTML = result + '<br/><input type="hidden" name="MAX_FILE_SIZE" value="5000000">File: <input name="myfile" type="file" accept="image/*" size="0" /><input type="submit" name="submitBtn" class="mysbtn" value="Upload" />'; document.getElementById('myf1_upload_form').style.visibility = 'visible'; return true; } |
function stopUpload(success, fileurl){ да, об этом забивал :) спасибо! |
Часовой пояс GMT +3, время: 13:37. |