Jump to content

Image isnt being accepted


divinedesigns1

Recommended Posts

ok samething that happen the last time, instead of accepting the image which is 65kb it keep on rejecting the image and giving the output "image need to be gif, jpeg or png with a size no more than 65kb but the image is 5.61kb 0.o http://www.divinedesigns1.com/demo/addon.php and this the script "once again just give me a hint if i mess up please and thank you

<?phprequire_once 'skimg.php';require_once 'my_connect.php';if (isset($_POST['submit'])) {// Grab the score data from the POST$name = $_POST['name'];$score = $_POST['score'];$screenshot = $_FILES['screenshot']['name'];$screenshot_type = $_FILES['screenshot']['type'];$screenshot_size = $_FILES['screenshot']['size'];if (!empty($name) && !empty($score)) {if((($screenshot_type == 'photos/gif') || ($screenshot_type == 'photos/jpeg') || ($screenshot_type == 'photos/pjpeg') || ($screenshot_type == 'photos/png')) && ($screenshot_size > 0) && ($screenshot_size <= SK_MAXFILESIZE)){if($_FILES['file']['error'] == 0){//Move the file to the target upload folder$target = SK_UPLOADPATH . $screenshot;if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {// Connect to the database$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);// Write the data to the database$query = "INSERT INTO scorekeeper VALUES (0, NOW(), '$name', '$score', '$screenshot', 0)";mysqli_query($conn, $query);// Confirm success with the userecho '<p>Thanks for adding your new high score!</p>';echo '<p><strong>Name:</strong> ' . $name . '<br />';echo '<strong>Score:</strong> ' . $score . '</p>';echo '<img src="' . SK_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';echo '<p><a href="index.php"><< Back to high scores</a></p>';// Clear the score data to clear the form$name = "";$score = "";$screenshot = "";mysqli_close($conn);}else {echo '<p class="error">Sorry there was a problem uploading your screen shot image</p>';}}}else{echo '<p class="error">The screen shot must be a GIF, JPEG OR PNG image file no' . 'greater than ' . (SK_MAXFILESIZE /1024) . ' KB in size.</p>';}// Try to delete the temporary screen shot image file@unlink ($_FILES['screenshot']['tmp_name']);}else{echo '<p class="error">Please enter all of the information to add your high score.</p>';}}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo SK_MAXFILESIZE; ?>" /><label for="name">Name: </label><input type="text" id="name" name="name" value="<?php if(!empty($name)) echo $name; ?>" /><br /><label for="score">Score: </label><input type="text" id="score" name="score" value="<?php if(!empty($score)) echo $score; ?>" /><br /><label for="screenshot">Screen Shot: </label><input type="file" id="screenshot" name="screenshot" /><hr /><input type="submit" value="Add" name="submit" /></form>

the image size script

<?php//define the upload pathdefine('SK_UPLOADPATH', 'photos/');define('SK_MAXFILESIZE', 65536); // 65 KB?>

so the max file size is 65kb and the addon script should accept only files that is 65kb or less but nothing happensi fixed this script before then i got help to fix it again from boen now im having problem again 0.o

Link to comment
Share on other sites

yes it, i change it to image and it worked perfectly well but yesterday it was working with photo

Link to comment
Share on other sites

  • 2 months later...

Hi PPL. I am having the same problem with this code not accepting the image. I am getting the following error when running this code from the Head First example."Sorry, there was a problem uploading your screen shot image."I dont understand the reason why I have this problem with the same code you mentioned above.Can you please help me resolve it.

Link to comment
Share on other sites

else {echo $_FILES['file']['error']; //<==add it here an note the number it printsecho '<p class="error">Sorry there was a problem uploading your screen shot image</p>';}http://au.php.net/manual/en/features.file-upload.errors.php check out the error number in this page and match with your printed error number.it will tell you the reason.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...