Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 03-14-2013, 10:59 AM
Disco_Dave's Avatar
Disco_Dave Disco_Dave is offline
 
Join Date: May 2011
Location: Belfast
Posts: 586
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Our own crud image uploader

Hi Guys/Gals

We use this uploader for non members on our site, we used this to insert the button in ckeditor: https://vborg.vbsupport.ru/showthread.php?t=278828

My question is how hard would it be to make this integrate into our site? It works but I'd like it to use usergroup variables if that makes sense. So that each user can find there pics easier.




PHP Code:
<?php 



// filename: upload.success.php 



?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 

"http://www.w3.org/TR/html4/strict.dtd"> 



<html lang="en"> 

    <head> 

        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 

         

        <link rel="stylesheet" type="text/css" href="stylesheet.css"> 

         

        <title>Successful upload</title> 

        

    <SCRIPT TYPE="text/javascript">

    <!--

        function targetopener(mylink, closeme, closeonly)

        {

            if (! (window.focus && window.opener))return true;

            window.opener.focus();

            if (! closeonly)window.opener.location.href=mylink.href;

            if (closeme)window.close();

            return false;

        }

    //-->

    </SCRIPT>



     

    </head> 

     

    <body> 

     

        <div id="Upload" > 

            <h1>File Upload Centre</h1> 

            <?php $uploadurl 'http://' $_SERVER['HTTP_HOST'] .'/forums/upload/uploaded_files/'$_GET['filename'?> 
            
            The following file uploaded successfully</br></br>
            <?php echo $uploadurl ?></br></br>
            Use this text in your threads, posts, signature...</br></br>
            <bw>[img]<?php echo $uploadurl ?>[/img]</bw>
            </br></br>


            Please copy the url highlighted above and paste in your message</br>
            If url copied you may close this window

            

        </div> 

     

    </body> 



</html>



PHP Code:
<?php 

// filename: upload.processor.php 

// first let's set some variables 

// make a note of the current working directory, relative to root. 
$directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']); 

// make a note of the directory that will recieve the uploaded file 
$uploadsDirectory $_SERVER['DOCUMENT_ROOT'] . $directory_self 'uploaded_files/'

// make a note of the location of the upload form in case we need it 
$uploadForm 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.form.php'

// make a note of the location of the success page 
$uploadSuccess 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.success.php'

// fieldname used within the file <input> of the HTML form 
$fieldname 'file'

// Now let's deal with the upload 

// possible PHP upload errors 
$errors = array(=> 'php.ini max file size exceeded'
                
=> 'html form max file size exceeded'
                
=> 'file upload was only partial'
                
=> 'no file was attached'); 

// check the upload form was actually submitted else print the form 
isset($_POST['submit']) 
    or 
error('the upload form is neaded'$uploadForm); 

// check for PHP's built-in uploading errors 
($_FILES[$fieldname]['error'] == 0
    or 
error($errors[$_FILES[$fieldname]['error']], $uploadForm); 
     
// check that the file we are working on really was the subject of an HTTP upload 
@is_uploaded_file($_FILES[$fieldname]['tmp_name']) 
    or 
error('not an HTTP upload'$uploadForm); 
     
// validation... since this is an image upload script we should run a check   
// to make sure the uploaded file is in fact an image. Here is a simple check: 
// getimagesize() returns false if the file tested is not an image. 
@getimagesize($_FILES[$fieldname]['tmp_name']) 
    or 
error('only image uploads are allowed'$uploadForm); 
     
// make a unique filename for the uploaded file and check it is not already 
// taken... if it is already taken keep trying until we find a vacant one 
// sample filename: 1140732936-filename.jpg 
$now time(); 
while(
file_exists($uploadFilename $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) 

    
$now++; 


// now let's move the file to its final location and allocate the new filename to it 
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename
    or 
error('receiving directory insuffiecient permission'$uploadForm); 
     
// If you got this far, everything has worked and the file has been successfully saved. 
// We are now going to redirect the client to a success page. 
header('Location: ' $uploadSuccess."?filename=".str_replace($uploadsDirectory,"",$uploadFilename)); 

// The following function is an error handler which is used 
// to output an HTML error page if the file upload fails 
function error($error$location$seconds 5

    
header("Refresh: $seconds; URL=\"$location\""); 
    echo 
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n"
    
'"http://www.w3.org/TR/html4/strict.dtd">'."\n\n"
    
'<html lang="en">'."\n"
    
'    <head>'."\n"
    
'        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n"
    
'        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n"
    
'    <title>Upload error</title>'."\n\n"
    
'    </head>'."\n\n"
    
'    <body>'."\n\n"
    
'    <div id="Upload">'."\n\n"
    
'        <h1>Upload failure</h1>'."\n\n"
    
'        <p>An error has occured: '."\n\n"
    
'        <span class="red">' $error '...</span>'."\n\n"
    
'         The upload form is reloading</p>'."\n\n"
    
'     </div>'."\n\n"
    
'</html>'
    exit; 
// end error handler 

?>



PHP Code:
<?php 

// filename: upload.form.php 

// first let's set some variables 

// make a note of the current working directory relative to root. 
$directory_self str_replace(basename($_SERVER['PHP_SELF']), ''$_SERVER['PHP_SELF']); 

// make a note of the location of the upload handler script 
$uploadHandler 'http://' $_SERVER['HTTP_HOST'] . $directory_self 'upload.processor.php'

// set a max file size for the html upload form 
$max_file_size 500000// size in bytes 

// now echo the html page 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd"> 

<html lang="en"> 
    <head> 
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 
     
        <link rel="stylesheet" type="text/css" href="stylesheet.css"> 
         
        <title>Upload form</title> 
     
    </head> 
     
    <body> 
     
    <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post"> 
     
        <h1> 
            Upload form 
        </h1> 
       
        <p> 
            Max File Size <?php echo $max_file_size ?> Bytes
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> 
        </p> 
         
        <p> 
            <label for="file">File to upload:</label> 
            <input id="file" type="file" name="file"> 
        </p> 
                 
        <p> 
            <label for="submit">Press to...</label> 
            <input id="submit" type="submit" name="submit" value="Upload me!"> 
        </p> 
   <center><img src="header_logo.png" alt="logo"/></center></br>
    </form> 
     
     
    </body> 

</html>
Cheers
Dave
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:59 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03727 seconds
  • Memory Usage 2,209KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete