Jump to content

Search the Community

Showing results for tags 'upload image'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. Hi, I have a user edit page that I cannot seem to get working correctly. We recently set out to add the addition of a avatar to our page. So... We edited the code and everything is working great for everyone but me. When I press submit on the form it sends me to a internal server error page instead of preloading the current page I am on. Everything that should get updated still does the only problem is the page will not load properly afterwards. I am at a complete wall and dont know where else to look. I was able to find out that if I remove a specific block of code the the page will reload but the picture will not update. 1. Picture wont upload but page will reload. 2. Picture will upload as expected but page doesnt reload correctly. Complete page code. <?php error_reporting(0); require('includes/application_top.php'); require('includes/classes/crypto.php'); $crypto = new phpFreaksCrypto; include('includes/classes/class.formvalidation.php'); include('includes/classes/class.phpmailer.php'); if (isset($_POST['submit'])) { $my_form = new validator; $mail = new PHPMailer(); if($_POST['password'] !== ''){ if($my_form->checkEmail($_POST['email'])) { // check for good mail if ($my_form->validate_fields('firstname,lastname,email,password')) { // comma delimited list of the required form fields if ($_POST['password'] == $_POST['password2']) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } $salt = substr($crypto->encrypt((uniqid(mt_rand(), true))), 0, 10); $secure_password = $crypto->encrypt($salt . $crypto->encrypt($_POST['password'])); $sql = "update " . $db_prefix . "users "; $sql .= "set password = '".$secure_password."', salt = '".$salt."', firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."', email = '".$_POST['email']."', template_name = '".$_POST['template_name']."' "; $sql .= "where userID = " . $user->userID . ";"; //die($sql); mysql_query($sql) or die(mysql_error()); //set confirmation message header('Location: index.php'); } else { $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>'; } } else { $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error); $display = '<div class="responseError">' . $display . '</div><br/>'; } } else { $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>'; } } elseif ($_post['password'] == ''){ if($my_form->checkEmail($_POST['email'])) { // check for good mail $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } if ($my_form->validate_fields('firstname,lastname,email, template_name')) { // comma delimited list of the required form fields if ($_POST['password'] == '') { $sql = "update " . $db_prefix . "users "; $sql .= "set firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."', email = '".$_POST['email']."', template_name = '".$_POST['template_name']."' "; $sql .= "where userID = " . $user->userID . ";"; //die($sql); mysql_query($sql) or die(mysql_error()); //set confirmation message header('Location: index.php'); } else { $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>'; } } else { $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error); $display = '<div class="responseError">' . $display . '</div><br/>'; } } else { $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>'; } } else { $display = '<div class="responseError">You broke all the things</div><br/>'; } } include('includes/header.php'); $sql = "select * from " . $db_prefix . "users where userID = " . $user->userID; $query = mysql_query($sql); if (mysql_num_rows($query)) { $result = mysql_fetch_array($query); $firstname = $result['firstname']; $lastname = $result['lastname']; $email = $result['email']; $template_name = $result['template_name']; } if (!empty($_POST['firstname'])) $firstname = $_POST['firstname']; if (!empty($_POST['lastname'])) $lastname = $_POST['lastname']; if (!empty($_POST['email'])) $email = $_POST['email']; if (!empty($_POST['template_name'])) $template_name = $_POST['template_name']; ?> <h1>Edit User Account Details</h1> <?php if(isset($display)) echo $display; ?> <form action="user_edit.php" method="post" name="edituser" enctype="multipart/form-data"> <fieldset> <legend style="font-weight:bold;">Enter User Details:</legend> <table cellpadding="3" cellspacing="0" border="0"> <?php if ($isGuest) { ?> <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>" readonly></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>" readonly></td></tr> <tr><td>Email:</td><td><input type="text" name="email" value="NULL" size="30" readonly></td></tr> <?php } else { ?> <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>"></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>"></td></tr> <tr><td>Email:</td><td><input type="text" name="email" value="<?php echo $email; ?>" size="30"></td></tr> <?php } ?> <tr><td>Favorite Team:</td><td><?php $template =$result['template_name'];?> <select name="template_name" > <option name="template_name" value="<?php echo "$template_name"; ?>">Choose your team template</option> <option value="main">NFL</option> <option value="ARI">Cardinals</option> <option value="ATL">Falcons</option> <option value="BAL">Ravens</option> <option value="BUF">Bills</option> <option value="CAR">Panthers</option> <option value="CHI">Bears</option> <option value="CIN">Bengals</option> <option value="CLE">Browns</option> <option value="DAL">Cowboys</option> <option value="DEN">Broncos</option> <option value="DET">Lions</option> <option value="GB">Packers</option> <option value="HOU">Texans</option> <option value="IND">Colts</option> <option value="JAX">Jaguars</option> <option value="KC">Chiefs</option> <option value="MIA">Dolphins</option> <option value="MIN">Vikings</option> <option value="NE">Patriots</option> <option value="NO">Saints</option> <option value="NYG">Giants</option> <option value="NYJ">Jets</option> <option value="OAK">Raiders</option> <option value="PHI">Eagles</option> <option value="PIT">Steelers</option> <option value="SD">Chargers</option> <option value="SEA">Seahawks</option> <option value="SF">49ers</option> <option value="STL">Rams</option> <option value="TB">Buccaneers</option> <option value="TEN">Titans</option> <option value="WAS">Redskins</option> </select></td></tr> <tr><td> </td></tr> <?php if ($isGuest) { ?> <?php } else { ?> <tr><td>New Password:</td><td><input type="password" name="password"></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="password2"></td></tr> <?php } ?> <tr><td> </td></tr> <tr><td>Avatar:</td><td><input type="file" name="img" id="img" <?php if ($isGuest) { ?> disabled <?php } ?>></td></tr> <tr><td> </td><td> <?php $avatars = glob("upload/$user->userID.*"); if(!empty($avatars)) { $avatar = $avatars[0]; echo '<img style="width:20%;" src="'.$avatar.'">'; echo '<p>**Note Image must be smaller than 3MB.</p>'; echo '<input type="submit" name="submit" value="Submit"></td></tr>'; echo '</table></fieldset></form></table></fieldset>'; include('includes/footer.php'); } else { $avatar = 'upload/default.jpg'; echo '<img style="width:20%;" src="'.$avatar.'">'; echo '<p>No avatar set, please upload one.<br>Image must be smaller than 3MB.</p>'; echo '<input type="submit" name="submit" value="Submit"></td></tr>'; echo '</table></fieldset></form></table></fieldset>'; include('includes/footer.php'); } require 'includes/correctImageOrientation.php'; correctImageOrientation('upload/'); ?> If I remove this specific piece of code then I have the case where the page loads fine but picture wont upload. $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } I attached the include file that I am using in case that is helpful as well. I am using php5.4 fastCGI on a godaddy server(plesk windows hosting) correctImageOrientation.php
  2. Hi Ultimate Aim: To upload multiple images using ajax using a PHP script which will be fired once an image is selected and then return the resulting URL for use in rest of my JS http://peter-gosling.com/testupload/chooseimage.html simple form posts to http://peter-gosling.com/testupload/saveimage.php This PHP script below currently gets the posted image and assigns it a random number file name and echos this <?php header("Access-Control-Allow-Origin: *"); $uploaddir = '/home/petergos/public_html/testupload/images/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $urlpath = "http://www.peter-gosling.co.uk/testupload/images/"; $temp = explode(".",$_FILES["userfile"]["name"]); $newfilename = rand(1,999999999) . '.' .end($temp); $newuploadfile = $uploaddir . $newfilename; echo "<p>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newuploadfile)) { $urlfile = $urlpath . $newfilename; echo $urlfile; } else { echo "Upload failed"; } ?> What I want to do is post my image via ajax but return the value back to my js file I'm not certain on the CORS issue Here's my first attempt http://peter-gosling.com/testupload/ HTML <!DOCTYPE html> <html> <head> </head> <body> <input type="file" accept="image/*;capture=camera" name="taskoutputfile"></input> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> $("input[name=taskoutputfile]").on("change", function (){ var fileName = $(this).val(); console.log(fileName); get_image_url(fileName) }); //UPLOAD IMAGE RETURN URL function get_image_url(imageurl) { var dataString = "url="+imageurl; //datastring = $("input[name=sessiontitle]").val(); //AJAX code to submit form. $.ajax({ type: "POST", url: "http://www.peter-gosling.co.uk/testupload/saveimage2.php", data: dataString, cache: false, success: function(html) { alert(html); } }); } </script> </body> </html> PHP <?php header("Access-Control-Allow-Origin: *"); $uploaddir = '/home/petergos/public_html/testupload/images/'; $uploadfile = $uploaddir . basename($_POST['url']); $urlpath = "http://www.peter-gosling.co.uk/testupload/images/"; $temp = explode(".",$_POST['url']); $newfilename = rand(1,999999999) . '.' .end($temp); $newuploadfile = $uploaddir . $newfilename; echo "<p>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newuploadfile)) { $urlfile = $urlpath . $newfilename; return $urlfile; } else { echo "Upload failed"; } /* echo "</p>"; echo '<pre>'; echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; */ ?> Have attached all files Any help would be really appreciated Thankyou
×
×
  • 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.