Jump to content

Recommended Posts

Hey all, I have a file upload script that I've used before, but for some reason now it's not working.  I'm not getting any errors, even in the $_FILES array.  It doesn't move the uploaded file, which is the only error that appears to happen.  Here's my code:

<?php
$max_image_size = '15360'; // this has to be in bytes
								$max_image_width = '80'; // in pixels
								$max_image_height = '80';
								$image_accepted=array('image/jpg','image/gif','image/png');
								if ($_FILES['url']['size'] > $max_image_size){ //If the file size is greater than 500000b

									$error='Your file size must be less than <strong>15kb</strong>!<br />';
									error_msg($error);
									exit();

								}
								if (!in_array($_FILES['url']['type'], $image_accepted))
								{
									$error='Image is not one of the accepted types.';
									error_msg($error);
									exit();
								}
								$dim=getimagesize($_FILES['url']['tmp_name']);
								if ($dim[0] > $max_image_width || $dim[0] > $max_image_height)
								{
									$error='Image uploaded is too big.';
									error_msg($error);
									exit();
								}

								$folder = "/items/";
								$newimagename=$folder . $_FILES['url']['name'];
									if(move_uploaded_file($_FILES['url']['temp_name'], $newimagename))
									{
										$url=$folder . basename($_FILES['url']['name']);
									}
									else{
										print_r($_FILES);
										echo$newimagename;
										$error="File could not be uploaded.<br />";
										error_msg($error);
										exit();}
							}

							$addnew = mysql_query("INSERT INTO item_list(name,description,category,amount,url,shop_price,rarity) VALUES ('$name','$desc','$cat','$amount','$url','$price','$rarity')") or die(mysql_error());
							if($addnew){
								for($i=0;$i<$amount; $i++){
								$additems=mysql_query("INSERT INTO items(category,name)VALUES('$cat','$name')");
								}
								echo'Item '.$name.' has been created!';
								}?>

Any help would be appreciated.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/117984-solved-file-upload-script-not-working/
Share on other sites

Start by turning on full php error reporting to find out why the function call is failing. Add the following two lines immediately after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.