Jump to content

Bottyz

Members
  • Posts

    107
  • Joined

  • Last visited

About Bottyz

  • Birthday 02/23/1986

Profile Information

  • Gender
    Male
  • Location
    England!

Bottyz's Achievements

Member

Member (2/5)

0

Reputation

  1. thank you, this seemed to work. I did try a foreach loop before you sent this but ended up causing another error: PHP Warning: Invalid argument supplied for foreach(). Your fix about makes perfect sense and so far has fixed my problem
  2. Thanks for your detailed answer, I've replaced my code with the above and its no longer causing an error and the download still works so I'm assuming it works as intended With regards to the unicode_replace_entities function. This is being passed a user inputted message from a message box on a contact form on the website. Its called as follows: function previous_request_value($str) { if (isset($_REQUEST[$str]) ) return $_REQUEST[$str]; else return ''; } $message_body = trim(previous_request_value('message_body')); $message_body=nl2br(htmlspecialchars(stripslashes($message_body), ENT_QUOTES, 'UTF-8')); $oUnicodeReplace = new unicode_replace_entities(); $message_body = $oUnicodeReplace->UTF8entities($message_body); Then the full class for unicode_replace_entities is: class unicode_replace_entities { public function UTF8entities($content="") { $contents = $this->unicode_string_to_array($content); $swap = ""; $iCount = count($contents); for ($o=0;$o<$iCount;$o++) { $contents[$o] = $this->unicode_entity_replace($contents[$o]); $swap .= $contents[$o]; } return mb_convert_encoding($swap,"UTF-8"); //not really necessary, but why not. } public function unicode_string_to_array( $string ) { //adjwilli $strlen = mb_strlen($string); $array = ""; while ($strlen) { $array[] = mb_substr( $string, 0, 1, "UTF-8" ); $string = mb_substr( $string, 1, $strlen, "UTF-8" ); $strlen = mb_strlen( $string ); } return $array; } public function unicode_entity_replace($c) { //m. perez $h = ord($c{0}); if ($h <= 0x7F) { return $c; } else if ($h < 0xC2) { return $c; } if ($h <= 0xDF) { $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); $h = "" . $h . ";"; return $h; } else if ($h <= 0xEF) { $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F); $h = "" . $h . ";"; return $h; } else if ($h <= 0xF4) { $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F); $h = "" . $h . ";"; return $h; } } } As you can tell some of this is not my code, and I can't confess to fully understanding all of it.
  3. For a start the session_start needs to go above everything else. The blank page would normally mean you've missing a semi colon or similar (best to check error logs for specifics) my guess would be the missing semi-colon from: mail($to, $subject, $message, $headers) should be: mail($to, $subject, $message, $headers);
  4. Just a thought, have you added <?php session_start(); ?> at the beginning of your email.php? You'll also want to keep the user on that page for a few seconds before redirecting to index.html as you'll want them to see the notice you've written, so add header ("refresh: 5; url=index.html"); instead of header("Location: index.html");
  5. Oh and I'm also getting a very similar PHP notice for the below, again I think the culprit is the $o variable. class unicode_replace_entities { public function UTF8entities($content="") { $contents = $this->unicode_string_to_array($content); $swap = ""; $iCount = count($contents); for ($o=0;$o<$iCount;$o++) { $contents[$o] = $this->unicode_entity_replace($contents[$o]); $swap .= $contents[$o]; } return mb_convert_encoding($swap,"UTF-8"); //not really necessary, but why not. } This time the notice is: [28-Jul-2015 06:44:41 America/New_York] PHP Notice: Uninitialized string offset: 0 in /public_html/contactform.php on line 108 Pulling what little hair I have left out over these! Thanks
  6. $domains = count($alloweddomains); for($y=0;$y<$domains+1;$y++) { if((stristr($_SERVER['HTTP_REFERER'], $alloweddomains[$y]))) { $allowed = 1; } } Hi all, Probably a really easy one for you to solve, but I'm a little stumped. I've recently upgraded to php 5.4 and have started getting a few php notices and I'm going through them one by one, but I'm stuck fixing the following: [29-Jul-2015 06:54:21 America/New_York] PHP Notice: Undefined offset: 3 in /public_html/filedownload.php on line 25 I've attached the code and I believe its referring to the $y variable. Any ideas or assistance is always appreciated.
  7. you could add an additional field to the comments table such as postid and have it store which post number the comment belongs to?
  8. I'll post some of the code below, but I'm not 100% sure how it all works as JSON is involved (Which i'm only just getting familiar with), so please bear with me. upload.html - client side where file upload is requested and form where title is entered by users. <form id="fileupload" action="server/php/" method="POST" enctype="multipart/form-data"> <!-- The template to display files available for upload --> <script id="template-upload" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-upload fade"> <td class="preview"><span class="fade"></span></td> <td class="name"><span>{%=file.name%}</span></td> <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> // my additional code here: <td class="caption"><label>Photo Title: <input name="title[]" required></label></td> {% if (file.error) { %} <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td> // end of my code {% } else if (o.files.valid && !i) { %} <td> <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div> </td> <td class="start">{% if (!o.options.autoUpload) { %} <button class="btn btn-primary"> <i class="icon-upload icon-white"></i> <span>{%=locale.fileupload.start%}</span> </button> {% } %}</td> {% } else { %} <td colspan="2"></td> {% } %} <td class="cancel">{% if (!i) { %} <button class="btn btn-warning"> <i class="icon-ban-circle icon-white"></i> <span>{%=locale.fileupload.cancel%}</span> </button> {% } %}</td> </tr> {% } %} </script> server/php/index.php - called by the form submission above (not sure if you need to see this part but thought it may help) session_start(); error_reporting(E_ALL | E_STRICT); require('upload.class.php'); $upload_handler = new UploadHandler(); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Content-Disposition: inline; filename="files.json"'); header('X-Content-Type-Options: nosniff'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); switch ($_SERVER['REQUEST_METHOD']) { case 'OPTIONS': break; case 'HEAD': case 'GET': $upload_handler->get(); break; case 'POST': if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { $upload_handler->delete(); } else { $upload_handler->post(); } break; case 'DELETE': $upload_handler->delete(); break; default: header('HTTP/1.1 405 Method Not Allowed'); } server/phpupload.class.php - Stores the classes which are probably causing the issue. I've tried to crop out most of the non relevant code. I've marked my edited code so you can see what I've changed as originally this script had no sort of mysql connection. class UploadHandler { protected $options; function __construct($options=null) { $this->options = array( 'script_url' => $this->getFullUrl().'/', 'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/img/', 'upload_url' => $this->getFullUrl().'/img/', 'param_name' => 'files', // Set the following option to 'POST', if your server does not support // DELETE requests. This is a parameter sent to the client: 'delete_type' => 'DELETE', // The php.ini settings upload_max_filesize and post_max_size // take precedence over the following max_file_size setting: 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/\.(gif|jpe?g|png)$/i', // The maximum number of files for the upload directory: 'max_number_of_files' => null, // Image resolution restrictions: 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, // Set the following option to false to enable resumable uploads: 'discard_aborted_uploads' => true, // Set to true to rotate images based on EXIF meta data, if available: 'orient_image' => true, 'image_versions' => array( // Uncomment the following version to restrict the size of // uploaded images. You can also add additional versions with // their own upload directories: 'large' => array( 'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/img/', 'upload_url' => $this->getFullUrl().'/img/', 'max_width' => 1920, 'max_height' => 1200, 'jpeg_quality' => 95 ), 'thumbnail' => array( 'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/thumbs/', 'upload_url' => $this->getFullUrl().'/thumbs/', 'max_width' => 75, 'max_height' => 75 ) ) ); if ($options) { $this->options = array_replace_recursive($this->options, $options); } } protected function getFullUrl() { $https = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; return ($https ? 'https://' : 'http://'). (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. ($https && $_SERVER['SERVER_PORT'] === 443 || $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); } protected function get_file_object($file_name) { $file_path = $this->options['upload_dir'].$file_name; if (is_file($file_path) && $file_name[0] !== '.') { $file = new stdClass(); $file->name = $file_name; $file->size = filesize($file_path); $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if (is_file($options['upload_dir'].$file_name)) { $file->{$version.'_url'} = $options['upload_url'] .rawurlencode($file->name); } } $this->set_file_delete_url($file); return $file; } return null; } protected function get_file_objects() { return array_values(array_filter(array_map( array($this, 'get_file_object'), scandir($this->options['upload_dir']) ))); } protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $title) { //My code: // connect to db to retrieve next file number include('../../../../../db/gallerypass.php'); $idstmt = $mysqli->stmt_init(); if ($idstmt = $mysqli->prepare("SELECT max(id) FROM gallery")){ $idstmt->execute(); $idstmt->bind_result($idnum); $idstmt->fetch(); $idstmt->close(); } // if query errors sends an email if ($mysqli->error) { try { throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $mysqli->errno); } catch(Exception $e ) { $mess = "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br>"; $mess .= nl2br($e->getTraceAsString()); $contact_email = "user@user.com"; $message_sub = "Mysqli Query Error [uPFAIL]"; $hdrs = "From: " . $contact_email . "\r\n"; $hdrs .= "Reply-To: ". $contact_email . "\r\n"; $hdrs .= "MIME-Version: 1.0\r\n"; $hdrs .= "Content-Type: text/html; charset=UTF-8\r\n"; mail($contact_email, $message_sub, $mess, $hdrs); } header("location: http://website.co.uk/"); exit(); } $mysqli->close(); $ext = strtolower(substr(strrchr($name, '.'), 1)); if ($ext == 'jpg') { $ext = 'jpeg'; } $idnum++; $name = $idnum . '.' . $ext; // End My Code $file = new stdClass(); $file->name = $this->trim_file_name($idnum, $type, $index); $file->size = intval($size); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index)) { $this->handle_form_data($file, $index); $file_path = $this->options['upload_dir'].$file->name; $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents( $file_path, fopen($uploaded_file, 'r'), FILE_APPEND ); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents( $file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0 ); } $file_size = filesize($file_path); if ($file_size === $file->size) { if ($this->options['orient_image']) { $this->orient_image($file_path); } $file->url = $this->options['upload_url'].rawurlencode($file->name); foreach($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->name, $options)) { if ($this->options['upload_dir'] !== $options['upload_dir']) { $file->{$version.'_url'} = $options['upload_url'] .rawurlencode($file->name); } else { clearstatcache(); $file_size = filesize($file_path); } } } } else if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } $file->size = $file_size; $this->set_file_delete_url($file); } // My Code: // connect to db to record file name & caption include('../../../../../db/gallerypass.php'); $null = NULL; $address = $_SERVER['REMOTE_ADDR']; $recordimgstmt = $mysqli->stmt_init(); if ($recordimgstmt->prepare("INSERT INTO gallery VALUES (?, ?, ?, ?)")) { $recordimgstmt->bind_param('isss', $null, $name, $title, $address); $recordimgstmt->execute(); $recordimgstmt->close(); } // if query errors sends an email if ($mysqli->error) { try { throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $mysqli->errno); } catch(Exception $e ) { $mess = "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br>"; $mess .= nl2br($e->getTraceAsString()); $contact_email = "user@user.com"; $message_sub = "Mysqli Query Error [uAIMGDB]"; $hdrs = "From: " . $contact_email . "\r\n"; $hdrs .= "Reply-To: ". $contact_email . "\r\n"; $hdrs .= "MIME-Version: 1.0\r\n"; $hdrs .= "Content-Type: text/html; charset=UTF-8\r\n"; mail($contact_email, $message_sub, $mess, $hdrs); } exit(); } $mysqli->close(); // End My Code return $file; } public function get() { $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; if ($file_name) { $info = $this->get_file_object($file_name); } else { $info = $this->get_file_objects(); } header('Content-type: application/json'); echo json_encode($info); } public function post() { if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { return $this->delete(); } $upload = isset($_FILES[$this->options['param_name']]) ? $_FILES[$this->options['param_name']] : null; $info = array(); if ($upload && is_array($upload['tmp_name'])) { // param_name is an array identifier like "files[]", // $_FILES is a multi-dimensional array: foreach ($upload['tmp_name'] as $index => $value) { $info[] = $this->handle_file_upload( $upload['tmp_name'][$index], isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], $upload['error'][$index], // My code to pass the input title $_REQUEST['title'] // end of my code ); } } elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) { // param_name is a single object identifier like "file", // $_FILES is a one-dimensional array: $info[] = $this->handle_file_upload( isset($upload['tmp_name']) ? $upload['tmp_name'] : null, isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : (isset($upload['name']) ? $upload['name'] : null), isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : (isset($upload['size']) ? $upload['size'] : null), isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : (isset($upload['type']) ? $upload['type'] : null), isset($upload['error']) ? $upload['error'] : null ); } header('Vary: Accept'); $json = json_encode($info); $redirect = isset($_REQUEST['redirect']) ? stripslashes($_REQUEST['redirect']) : null; if ($redirect) { header('Location: '.sprintf($redirect, rawurlencode($json))); return; } if (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) { header('Content-type: application/json'); } else { header('Content-type: text/plain'); } echo $json; } } I also edited the main javascript file: $('#fileupload').bind('fileuploadsubmit', function (e, data) { var inputs = data.context.find(':input'); if (inputs.filter('[required][value=""]').first().focus().length) { return false; } data.formData = inputs.serializeArray(); }); As you can see from above I thought that js may be serializing the data so I did try to use unserialize() around the title variable but this didn't change anything either. Anyone with a better understanding able to help? I'd very much appreciate it.
  9. hi all, i'm attempting to use the file upload script by blueimp: https://github.com/blueimp/jQuery-File-Upload in order to upload and store images for an image gallery. I've added a mysql script to store a title for each image to retrieve when showing them in the gallery. now my problem is that when I try to store the title all it stores (when looking through phpmyadmin) is the word 'array'. I've tried a few variations of trying to extract the information such as var_dump or printr and all I seem to manage to get out of it is string(5). I'm not great with my knowledge on arrays so if someone can offer any ideas on how to extract the title, that would be great, thanks!
  10. Awesome! I never thought to look in the tutorials, sorry! One other thing though, if wanted to also have the ability to pull 10 rows of customers into a page based on the first letter of their name, and still have the page 1, 2, 3 etc... could you point me in the right driection on how to do that? Thanks.
  11. Hi all, I have a database which contains customer details. We have a php script which pulls the records from the database and puts them into a table on the page. Currently, it fetches all the customer records. This wasn't such a problem when there was only a few customers in the db but this is a bit higher now! Is there any way I can modify the script to only show 20 per page and add links to page 2 etc along the bottom, which can be clicked to show the next 20 and so on? I can post my current code if need be, Thanks.
  12. Hi mikosiko, I figured that one out only a couple of days ago when sifting through the php manual. I forgot to update everyone here. But thanks for the confirmation! I just call each myslqi with a new connection using a pre-set dbconnect file.
  13. The problem is that all of the files are stored outside of the www root. We don't want the software etc to be downloaded without the right permissions, and we don't want the url openly available. I don't think I can do that with <object> containers. I've never used AJAX, but that is a type of javascript isn't it? So would it fall foul of people that don't have javascript enabled browsers? If not, I'll certainly have a closer look. Thanks for you comments thus far.
  14. Hi muddy, No, I use cURL for that. This is a download script in a login area for some of our customers. The script is for software zip files mainly, but the occassion pdf is used. I think it has to be something wrong with the connection to the website. The files need to be secured so that they can't be stolen. Is there anything else I can use to stop the connection dropping or anything other than php that is reliable and easy to use as an alternative?
  15. Hi all, Guessing no one can help with the problem? Or suggest any ideas? Anyways, I'm not sure if it is a problem with php but rather a problem with the setup of the host server? I just tried implementing the following code with the exact same results: /* Execution Time Unlimited */ set_time_limit(0); /* |---------------- | Header | Forcing a download using readfile() |---------------- */ header('Content-Description: File Transfer'); header('Content-Type: ' . $file_mime_type); header('Content-Disposition: attachment; filename=' . $file); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file_size); ob_clean(); flush(); readfile($file_path); exit; I'm running out of options now, and not sure what else to pursue. Does anyone have any alternatives they could suggest? Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.