PHP - Plugin Update, File Uploader And Sftp - On A Wordpress That Runs On Secured- Server
dear folks
this question is regarding the plugin update, file uploader and SFTP - on a wordpress that runs on secured- server
I think I know the answer to the following question as "not possible" but I figured I would check.
my sites are on servers where we disable FTP access and only use SFTP access, and also on a different port (not port 22). what if i want to use a automated maintaining service like the following https://mainwp.com http://wwww.infinitewp.com automated Installing and updating plugins to the sites does not seem to work and I assume this is the reason why. I'm also assuming the File uploader extension will not work either. Can anyone confirm this for sure though? Any ideas as far as workaround? one might think of the following way: Can you try adding your SFTP settings into the wp-config of one of my sites to see if that allows the functions to work? we can see an example in http://codex.wordpre...g_wp-config.php under WordPress Upgrade Constants or possibly try this plugin SSH SFTP Updater Support do you have any idear!? cf: https://mainwp.com/f...&highlight=sftp Similar TutorialsHi
I need to add one more function in my wordpress plugin. below is the sample code working for 2nd tier. Now i need a same function for 3rd and 4th tire.
Function explanation
I am A and i refer B and if B made any sale means I (A) will get direct commission for that sale.
If B refer C and if C made any sale means (B) will get direct commission for that sale. And in this sample code me(A) also get commission for that sale as a 2nd tier.
Now C refer D and if D made any sale means © will get direct commission for that sale and (B) will get 2nd tier commission. So here (A) me too should get 3rd tire commission and i need that function.
Please help me.
function wp_aff_award_second_tier_commission($wp_aff_affiliates_db,$sale_amount,$txn_id,$item_id,$buyer_email,$buyer_name='') { global $aff_tx_msg; $clientdate = (date ("Y-m-d")); $clienttime = (date ("H:i:s")); if (get_option('wp_aff_use_2tier') && !empty($wp_aff_affiliates_db->referrer)) { $aff_tx_msg .= '<br />Using tier model'; wp_affiliate_log_debug("Using tier model",true); $award_tier_commission = true; $duration = get_option('wp_aff_2nd_tier_duration'); if(!empty($duration)) { $join_date = $wp_aff_affiliates_db->date; $days_since_joined = round((strtotime(date("Y-m-d")) - strtotime($join_date) ) / (60 * 60 * 24)); if ($days_since_joined > $duration) { $aff_tx_msg .= '<br />Tier commission award duration expried'; wp_affiliate_log_debug("Tier commission award duration expried! No tier commission will be awarded for this sale.",true); $award_tier_commission = false; } } if ($award_tier_commission) { if(!empty($wp_aff_affiliates_db->sec_tier_commissionlevel)){ $second_tier_commission_level = $wp_aff_affiliates_db->sec_tier_commissionlevel; wp_affiliate_log_debug("Using the affiliate specific 2nd tier commission for this referral. 2nd tier commission level: ".$second_tier_commission_level,true); } else{ $second_tier_commission_level = get_option('wp_aff_2nd_tier_commission_level'); wp_affiliate_log_debug("Using global 2nd tier commission for this referral. 2nd tier commission level: ".$second_tier_commission_level,true); } if (get_option('wp_aff_use_fixed_commission')) { $commission_amount = $second_tier_commission_level; } else { $commission_amount = round(($second_tier_commission_level * $sale_amount)/100,2); } $campaign_id = ""; $is_tier_comm = "yes"; global $wpdb; $aff_sales_table = WP_AFF_SALES_TBL_NAME; $updatedb = "INSERT INTO $aff_sales_table (refid,date,time,browser,ipaddress,payment,sale_amount,txn_id,item_id,buyer_email,campaign_id,buyer_name,is_tier_comm) VALUES ('$wp_aff_affiliates_db->referrer','$clientdate','$clienttime','','','$commission_amount','$sale_amount','$txn_id','$item_id','$buyer_email','$campaign_id','$buyer_name','$is_tier_comm')"; $results = $wpdb->query($updatedb); $aff_tx_msg .= '<br />Tier commission awarded to: '.$wp_aff_affiliates_db->referrer.'. Commission amount: '.$commission_amount; wp_affiliate_log_debug('Tier commission awarded to: '.$wp_aff_affiliates_db->referrer.'. Commission amount: '.$commission_amount,true); } } return $aff_tx_msg; } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=314030.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=334215.0 <?php /** * Plugin Name: Esewa * Plugin URI: https://kamalparajuli.com.np * Author Name: Kamal Parajuli * Author URI: https://kamalparajuli.com.np * Description: This plugin allows for local content payment systems. * Version: 0.1.0 * License: 0.1.0 * License URL: http://www.gnu.org/licenses/gpl-2.0.txt * text-domain: pay-esewa */ if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) return; add_action( 'plugins_loaded', 'noob_payment_init', 11 ); function noob_payment_init() { if( class_exists( 'WC_Payment_Gateway' ) ) { class WC_Noob_pay_Gateway extends WC_Payment_Gateway { public function __construct() { $this->id = 'noob_payment'; $this->icon = apply_filters( 'woocommerce_noob_icon', plugins_url('/assets/icon.png', __FILE__ ) ); $this->has_fields = true; $this->method_title = __( 'Noob Payment', 'noob-pay-woo'); $this->method_description = __( 'Noob local content payment systems.', 'noob-pay-woo'); $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); $this->init_form_fields(); $this->init_settings(); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); // add_action( 'woocommerce_thank_you_' . $this->id, array( $this, 'thank_you_page' ) ); } public function init_form_fields() { $this->form_fields = apply_filters( 'woo_noob_pay_fields', array( 'enabled' => array( 'title' => __( 'Enable payment', 'noob-pay-woo'), 'type' => 'checkbox', 'label' => __( 'Tick mark means its enabled.', 'noob-pay-woo'), 'default' => 'no' ), 'title' => array( 'title' => __( 'Esewa Payment', 'noob-pay-woo'), 'type' => 'text', 'default' => __( 'Esewa Payment', 'noob-pay-woo'), 'desc_tip' => true, 'description' => __( 'Add a new title for the Esewa Payment that customers will see when they are in the checkout page.', 'noob-pay-woo') ), 'description' => array( 'title' => __( 'Esewa Payment Description', 'noob-pay-woo'), 'type' => 'textarea', 'default' => __( 'Please remit your payment to the shop to allow for the delivery to be made', 'noob-pay-woo'), 'desc_tip' => true, 'description' => __( 'Add a new title for the Esewa Payment that customers will see when they are in the checkout page.', 'noob-pay-woo') ), 'instructions' => array( 'title' => __( 'Instructions', 'noob-pay-woo'), 'type' => 'textarea', 'default' => __( 'Default instructions', 'noob-pay-woo'), 'desc_tip' => true, 'description' => __( 'Instructions that will be added to the thank you page and order email', 'noob-pay-woo') ), // 'enable_for_virtual' => array( // 'title' => __( 'Accept for virtual orders', 'woocommerce' ), // 'label' => __( 'Accept COD if the order is virtual', 'woocommerce' ), // 'type' => 'checkbox', // 'default' => 'yes', // ), )); } public function process_payments( $order_id ) { $order = wc_get_order( $order_id ); $order->update_status( 'on-hold', __( 'Awaiting Noob Payment', 'noob-pay-woo') ); // if ( $order->get_total() > 0 ) { // Mark as on-hold (we're awaiting the cheque). // } else { // $order->payment_complete(); // } // $this->clear_payment_with_api(); $order->reduce_order_stock(); WC()->cart->empty_cart(); return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ), ); } // public function clear_payment_with_api() { // } public function thank_you_page(){ if( $this->instructions ){ echo wpautop( $this->instructions ); } } } } } add_filter( 'woocommerce_payment_gateways', 'add_to_woo_noob_payment_gateway'); function add_to_woo_noob_payment_gateway( $gateways ) { $gateways[] = 'WC_Noob_pay_Gateway'; return $gateways; }
this is my plugin code. I want to display a QR code below the description so people can scan that qr code and pay. However I cannot understand how to let admin upload his/her Qr code and how to display it on checkout page just like description. Edited July 13 by Barandcode tags added This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=322006.0 I'm working with a Wordpress plugin that uses that google maps api to map multiple markers depending on search terms and proximity. You can set an option so that, regardless of the default proximity when the page loads, ALL markers will first appear. In order to help with performance, the authors decided to limit that option to 250 markers. I need to lift that limit to 5,000 (though I currently only have about 500, I don't want to deal with limits as my markers grow).
Based on a comment made in one of the php files it appears the authors enforce the limit in the query itself so I'm pasting the code for the php file that performs the query. Please let me know if there is something else I should do, if this forum is the wrong place or if I should be posting on pastebin and linking rather than dumping the entire file between code tags. Thanks in advance!
<?php if ( !class_exists( 'SM_XML_Search' ) ){ class SM_XML_Search{ // Register hook to perform the search function sm_xml_search() { add_action( 'template_redirect', array( &$this, 'init_search' ) ); } // Inits the search process. Collects default options, search options, and queries DB function init_search() { if ( isset( $_GET['sm-xml-search'] ) ) { global $wpdb, $simple_map; remove_filter( 'the_title', 'at_title_check' ); $defaults = array( 'lat' => false, 'lng' => false, 'radius' => false, 'namequery' => false, 'query_type' => 'distance', 'address' => false, 'city' => false, 'state' => false, 'zip' => false, 'onlyzip' => false, 'country' => false, 'limit' => false, 'pid' => 0, ); $input = array_filter( array_intersect_key( $_GET, $defaults ) ) + $defaults; $smtaxes = array(); if ( $taxonomies = get_object_taxonomies( 'sm-location' ) ) { foreach ( $taxonomies as $key => $tax ) { $phpsafe = str_replace( '-', '_', $tax ); $_GET += array( $phpsafe => '' ); $smtaxes[$tax] = $_GET[$phpsafe]; } } // Define my empty strings $distance_select = $distance_having = $distance_order = ''; // We're going to do a hard limit to 500 for now. if ( !$input['limit'] || $input['limit'] > 500 ) $limit = "LIMIT 500"; else $limit = 'LIMIT ' . absint( $input['limit'] ); $limit = apply_filters( 'sm-xml-search-limit', $limit ); // Locations within specific distance or just get them all? $distance_select = $wpdb->prepare( "( 3959 * ACOS( COS( RADIANS(%s) ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS(%s) ) + SIN( RADIANS(%s) ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance", $input['lat'], $input['lng'], $input['lat'] ) . ', '; $distance_order = 'distance, '; if ( $input['radius'] ) { $input['radius'] = ( $input['radius'] < 1 ) ? 1 : $input['radius']; $distance_having = $wpdb->prepare( "HAVING distance < %d", $input['radius'] ); } $i = 1; $taxonomy_join = ''; foreach ( array_filter( $smtaxes ) as $taxonomy => $tax_value ) { $term_ids = explode( ',', $tax_value ); if ( $term_ids[0] == 'OR' ) { unset( $term_ids[0] ); if ( empty( $term_ids ) ) { continue; } $search_values = array( "IN (" . vsprintf( '%d' . str_repeat( ',%d', count( $term_ids ) - 1 ), $term_ids ) . ")" ); } else { $search_values = array(); foreach ( $term_ids as $term_id ) { $search_values[] = sprintf( '= %d', $term_id ); } } foreach ( $search_values as $search_value ) { $taxonomy_join .= " INNER JOIN $wpdb->term_relationships AS term_rel_$i ON posts.ID = term_rel_$i.object_id INNER JOIN $wpdb->term_taxonomy AS tax_$i ON term_rel_$i.term_taxonomy_id = tax_$i.term_taxonomy_id AND tax_$i.taxonomy = '$taxonomy' AND tax_$i.term_id $search_value "; $i++; } } $sql = "SELECT lat_tbl.meta_value AS lat, lng_tbl.meta_value AS lng, $distance_select posts.ID, posts.post_content, posts.post_title FROM $wpdb->posts AS posts INNER JOIN $wpdb->postmeta lat_tbl ON lat_tbl.post_id = posts.ID AND lat_tbl.meta_key = 'location_lat' INNER JOIN $wpdb->postmeta lng_tbl ON lng_tbl.post_id = posts.ID AND lng_tbl.meta_key = 'location_lng' $taxonomy_join WHERE posts.post_type = 'sm-location' AND posts.post_status = 'publish' GROUP BY posts.ID $distance_having ORDER BY " . apply_filters( 'sm-location-sort-order', $distance_order . ' posts.post_name ASC', $input ) . " " . $limit; $sql = apply_filters( 'sm-xml-search-locations-sql', $sql ); // TODO: Consider using this to generate the marker node attributes in print_xml(). $location_field_map = array( 'location_address' => 'address', 'location_address2' => 'address2', 'location_city' => 'city', 'location_state' => 'state', 'location_zip' => 'zip', 'location_country' => 'country', 'location_phone' => 'phone', 'location_fax' => 'fax', 'location_email' => 'email', 'location_url' => 'url', 'location_special' => 'special', ); $options = $simple_map->get_options(); $show_permalink = !empty( $options['enable_permalinks'] ); if ( $locations = $wpdb->get_results( $sql ) ) { // Start looping through all locations i found in the radius foreach ( $locations as $key => $value ) { // Add postmeta data to location $custom_fields = get_post_custom( $value->ID ); foreach ( $location_field_map as $key => $field ) { if ( isset( $custom_fields[$key][0] ) ) { $value->$field = $custom_fields[$key][0]; } else { $value->$field = ''; } } $value->postid = $value->ID; $value->name = apply_filters( 'the_title', $value->post_title ); $the_content = trim( $value->post_content ); if ( !empty( $the_content ) ) { $the_content = apply_filters( 'the_content', $the_content ); } $value->description = $the_content; $value->permalink = ''; if ( $show_permalink ) { $value->permalink = get_permalink( $value->ID ); $value->permalink = apply_filters( 'the_permalink', $value->permalink ); } // List all terms for all taxonomies for this post $value->taxes = array(); foreach ( $smtaxes as $taxonomy => $tax_value ) { $phpsafe_tax = str_replace( '-', '_', $taxonomy ); $local_tax_names = ''; // Get all taxes for this post if ( $local_taxes = wp_get_object_terms( $value->ID, $taxonomy, array( 'fields' => 'names' ) ) ) { $local_tax_names = implode( ', ', $local_taxes ); } $value->taxes[$phpsafe_tax] = $local_tax_names; } } } else { // Print empty XML $locations = array(); } $locations = apply_filters( 'sm-xml-search-locations', $locations ); $this->print_json( $locations, $smtaxes ); } } // Prints the JSON output function print_json( $dataset, $smtaxes ) { header( 'Status: 200 OK', false, 200 ); header( 'Content-type: application/json' ); do_action( 'sm-xml-search-headers' ); do_action( 'sm-print-json', $dataset, $smtaxes ); echo json_encode( $dataset ); die(); } } } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=306092.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348006.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=323633.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=349156.0 I wanted to develop a Wordpress plugin. There's a few existing plugins for the subject I wanted to code. I thought I would get some inspiration by looking at the code. It's a gigantic mess of spaghetti! The code I looked at, looks like it's been made using an IDE. There seems to be so many folders and files - it's crazy. Others I looked at seem to be similar. It seems like an enterprise application. I'm more than capable of writing a spec and coding myself. The only thing I'm missing would be Wordpress practices - setting up tables and using hooks and other things. Any advice? Or do I just get dirty and sink my head into the code and untangle? QUESTIONS: - Do you use an IDE to code PHP? - What are the most popular IDE's? Thanks. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318539.0 Hi: I have written code that will allow a user to upload a file and that will allow the user to view/delete the image when clicking on the link. I'm having trouble in the table where the image information is organized - the table just duplicates information about an image into another column,.how can I fix this? Here's my code: Code: [Select] <? if ($handle = opendir('images/')) { while (false !== ($file = readdir($handle))) { $TPL['fileList'][] = array( 'fileName' => $file, 'fileSize' => filesize('images/'.$file), 'fileDate' => 'Jan 2, 2029' ); } } switch ($_REQUEST['act']): default: break; if (empty($_FILES['userfile']['name'])): $TPL['errMsg'] = "No file selected"; $TPL['dispErrMsg'] = true; break; endif; copy ($_FILES['userfile']['tmp_name'], 'images/'.$_FILES['userfile']['name']); break; case 'del': echo "delete this file? ($_GET)['userfile']['name']"; endswitch; ?> <html> <head> <title>Comp10065 - Lab 4: File Upload</title> <style type="text/css"> body {background-color:yellow} div#container {margin-right: auto; margin-left: auto; border: 1px solid #EEEEEE; width: 800px; padding: 10px; background-color:white} h1 {text-align: center; color:orange; background-color:white} table {width: 700px; margin-bottom: 15px} table th {text-align: left;padding: 0px 10 0px 10px} table td{padding: 0px 10 0px 10px; border: 1px solid #AAAAAA} tr.odd {background-color: #EEEEEE} tr.even {background-color: #CCCCCC} .message {color:red} div#debug {border: 1px solid #BBBBBB} </style> <script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js"></script> <script type="text/javascript"> function popup(img) { var day= new Date(); var windowParms = 'width=400,height=400,scrollbars,resizable'; var htmlPage = '<html><body><img src="' + img + '"><br>' + ' <form><input type="button" ' + ' onclick="javascript:window.close();" value="Close Window"><br>\n' + ' </form></body></html>\n'; var popupWindow = window.open('',day.getTime(),windowParms); popupWindow.document.write(htmlPage); popupWindow.document.close(); } </script> <script> $(function() { $("div#debug").hide(); $("a#debugLink").click(function () {$("div#debug").toggle("slowly"); }); }); </script> </head> <body > <div id="container"> <h1> Picture Uploader!</h1> <p>Click here to <a href="<?= $_SERVER['PHP_SELF'] ?>">refresh</a> this page.</p> <table> <tr> <th>File Name (<a href="upload.php?act=sortby&col=filename">sort</a>)</th> <th>Size KBytes (<a href="upload.php?act=sortby&col=size">sort</a>)</th> <th>Date</th> </tr> </td> <? foreach($TPL['fileList'] as $key => $val): ?> <td><a href="<?= 'images/'.$val['fileName'] ?>"><?=$val['fileName'] ?></a></td> <td><?= $val['fileName'] ?></td> <td><?= $val['fileSize'] ?></td> <td><?= $val['fileDate'] ?></td> <td><a href="#" onClick="popup('images/uieiuirdi.jpg')" >View</a></td> <td align=center><a href=upload.php?act=del&file=uieiuirdi.jpg>Delete</a></td> </tr> <? endforeach ?> </table> <p class="message">Records sorted by size</p> <form action=upload.php method="post" enctype='multipart/form-data'> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input type="hidden" name="act" value="post"> <input type="file" name="userfile" size="60" value=""> <br> <input type="submit" value="UPLOAD FILE" name="submit">Do not upload large files! </form> <? if($TPL['dispErrMsg']): ?> <p><?= $TPL['errMsg'] ?></p> <? endif; ?> <hr> <p>Click <a href="#" id = "debugLink"> here </a> for debug info. Jquery show/hide effect.</p> <div id="debug"> <p>This debug info is here to help you. You are only required to display the $_POST and $_FILES array</p> <pre > <? print_r($TPL) ?></pre> </div> </div> </body> </html> This has probably been asked here tons of times, and yes I've searched on google but I can't find a decently explained method. What I want is to be able to upload a whole directory of pictures at once. These pictures must go through the following: Be cropped in size (about 600px width/height) This must be stored in a folder under a random name A thumbnail must be made, with the same name, in another folder The location of each picture should be stored in a database What I've said here is all PHP I presume, and that I can take care of, I think. The problem is the multiuploader. I understand it can't be done in PHP, since PHP lets only 1 file per input tag, so you cannot select a directory. So this should be done with javascript/java/??? Additional questions: if I do mkdir('/pictures/$mapname/thumbs');, the 'pictures' already exists but the rest doesn't. Does it create the $mapname dir and the thumbs, or should I use 2 different mkdir's? What width is best to save the images to? What with is the best to save the thumbs to? So many more, but I'll keep it at this! I know it's a lot of questions, but it would really be handy if I could do this! Thanks in advance! Hi, Ive had a website for some time that allows people to upload pictures to certain directories, and each directory had its own upload script, I decided as Im slowley getting better at php to combine it all into 1 file and include it, all works great, but now I notice its a lot of repeated code as the only thing that changes for each function is the directory name, here is the script as it is: <?php // James Davies, Revised 2010 // Create the main NSFW upload function function demotivate() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/demotivate/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } function nsfw() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/nsfw/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } function fail() { //configure site specific variables $website = 'http://www.thenudedeer.com'; //what is the folder name $phpbbdir = '/fail/'; // Create an array containing all valid upload file types for this script $allowed_types = array( "image/gif" => "gif", "image/pjpeg" => "jpg", "image/jpg" => "jpg", "image/jpeg" => "jpg", "image/png" => "png", "image/x-png" => "png", // Add more types here if you like ); // Check to see if the file type is in the allowed types array if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) { die("Invalid file type."); } // Set the maximum uploadable file size => 512000 = 500kb $maxfilesize = 512000; // Is the file larger than it is allowed to be? if($_FILES['userfile']['size'] > $maxfilesize) { die("File too large"); } // Where will the file be uploaded to? $uploaddir = $_SERVER['DOCUMENT_ROOT'] . $phpbbdir; // What is the files temporary name? $file = $_FILES['userfile']['tmp_name']; // What is the files actual name? $filename = $_FILES['userfile']['name']; // Does this file already exist on the server? if(file_exists($uploaddir . $filename)) { //die("A file with that name already exists on this server."); die("File already existed, [img]http://" . $website . $phpbbdir . $filename ."[/img]"); } else { // This file does not already exist, so copy it. copy($file, $uploaddir.$filename) or die("Could not copy file."); } // All done! :-) echo "<br />"; echo "<font color=red><b>"; echo "Upload successful"; echo "<br />"; echo "Copy and Paste the following Code"; echo "</font><br/>"; echo "<font color='green'><b>"; echo "<br />"; echo "[img]http://" . $website . $phpbbdir . $filename; echo "[/img]"; echo "<br/>"; echo "<br/>"; echo '<img class="img" src="' .$phpbbdir .$filename.'">'; echo "<br />"; echo "<br />"; echo "</font>"; echo "<br /><br />"; } ?> there must be a way to stop repeating all the same code for each function? many thanks I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? Hey. I am wanting to move a couple of files from my current server to another. If i am uploading the file this is fine but if it is already on the server then im not sure how to move it. When uploading I can just use ftp_put($conn_id, $destination_file, $myFile, FTP_BINARY); What i need to do is figure out how to get a hold of the file and store it in $myFile then this would work fine. Is this possible? Cheers All, Looking for source exampe that lets you select between FTP, SFTP and SCP for file downloads, including ability to catalog all subdirectories and their files. Would appreciate quick shout with URL. Thanks! OMR Hi all I am pulling my hair out trying to get the following script to work Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect("*.*.*.*", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "root", "********")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // execute a command if (!($stream = ssh2_exec($con, "ls -al" ))) { echo "fail: unable to execute command\n"; } else { echo "should be ok"; // collect returning data from command stream_set_blocking($stream, true); $data = "path to file checked by logging into WINSCP and looking at properties. Is a .txt file"; echo $data; while ($buf = fread($stream,4096)) { $data .= $buf; } fclose($stream); } } } Basically shouldnt this display the contents of the file to me? On screen I just get Quote okay: logged in... should be ok What is my error? Thanks Hi there. I need help to update fields on another server from my server. <?php $dbhost1 = "dedi212.jnb2.host-h.net"; $dbuser1 = "gilan"; $dbpassword1 = "********"; $db1 = "risingfs_rcjan2010"; $connection1 = mysql_connect($dbhost1,$dbuser1,$dbpassword1) or die (mysql_error()); mysql_select_db($db1,$connection1); $dbhost2 = "41.66.140.74"; $dbuser2 = "*********"; $dbpassword2 = "**********"; $db2 = "edutoy"; $connection2 = mysql_connect($dbhost1,$dbuser1,$dbpassword1) or die (mysql_error()); mysql_select_db($db2,$connection2); $mysql_query =" INSERT INTO risingfs_rcjan2010.aa(risingfs_rcjan2010.aa.a,risingfs_rcjan2010.aa.b) SELECT edutoy.products.id,edutoy.products.NAME FROM edutoy.products.products } ?> |