Jump to content

Uploading an image and copying it to a folder


phplost1989

Recommended Posts

I'm trying to allow a user to upload an image, and have that image copied to an Image folder on the server

When I run the code I get the success message near the bottom of the code, but the image never gets copied to the folder. I'm not sure what's causing it to not copy the image

 

if($_POST["store"] != "") // if upload was hit
{
$fileExt = strrchr($_FILES['userfile']['name'], "."); // grab extension
if($fileExt != ".jpg" && $fileExt != ".jpeg") // check extension
{
	$_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt; // set error
}
else
{
	$fileName = $_FILES['userfile']['name']; // set file name
	if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) 
	{
		echo "Problem: possible file upload attack!"; // set error
		exit(); // end
	}

	$upfile = "../Images/lg_".$category.$counter.".jpg"; // set path
	$newFileName = $category.$counter.".jpg"; // set new file name
	if(!copy($_FILES['userfile']['tmp_name'], $upfile)) // if not able to copy
	{
		echo "Problem: file could not be copied to directory!"; // set error
		exit(); // end
	}
	$_SESSION["badfileType"] = "File uploaded successfully!"; // set success message
}
}
else
{
$_SESSION["badFileType"] = ""; // clear error
}

Link to comment
Share on other sites

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.