Jump to content

Problem uploading files


AdRock

Recommended Posts

I am having problems uploading an image.

 

I am testing it on a windows local machine with apache and this script used to work but now it doesn't.

 

I have narrowed it down to it not moving the image to the target folder.

 

Here are the errors

Warning: move_uploaded_file(./users/ScaryHair/profilepic/File0004201.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Apache\htdocs\folk\php\userfuncs.php  on line 294

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php5C.tmp' to './users/ScaryHair/profilepic/File0004201.jpg' in C:\Apache\htdocs\folk\php\userfuncs.php on line 294

 

and the code in question

$width = 130;
$height = 130;

$picture = $_FILES['imagefile']['name']; 
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { 
$imagename = $_FILES['imagefile']['name'];
$source = $_FILES['imagefile']['tmp_name'];
$target = "./users/".$_SESSION['username']."/profilepic/".$imagename;
if(move_uploaded_file($source, $target)) {
	return "uploaded";
	/*$profpic = $imagename;
	$save = "./users/".$_SESSION['username']."/profilepic/".$imagename; //This is the new file you saving
	$file = "./users/".$_SESSION['username']."/profilepic/".$imagename; //This is the original file

	$dimensions = getimagesize($file);
	// Prepare canvas
	$canvas = imagecreatetruecolor($width,$height);
	$piece = imagecreatefromjpeg($file);
	// Prepare image resizing and crop -- Center crop location
	$newwidth = $dimensions[0] * 1.3 / 2;
	$newheight = $dimensions[1] * 1.3 / 2;
	$cropLeft = ($newwidth/2) - ($width/2);
	$cropHeight = ($newheight/2) - ($height/2);
	// Generate the cropped image
	imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $width, $height, $newwidth, $newheight);
	// Write image or fail
	if (imagejpeg($canvas,$save,100)) {
		echo 'Image crop successful';
	} else {
		echo 'Image crop failed';
	}
	// Clean-up
	imagedestroy($canvas);
	imagedestroy($piece);*/
} else {
	return 'Failed to move image to target';
}
}
else {
return "You uploaded an invalid image format";
} 

 

Link to comment
https://forums.phpfreaks.com/topic/197744-problem-uploading-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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