Jump to content

[SOLVED] image upload


marcha

Recommended Posts

Hello there. Could you help me out with one thing please. This is a simple example with img upload which works fine just by itself. But when I add more input fields to form and then submit the form all the values are inserted into database but the picture isn't uploaded to specified directory.

 

what am I missing  ???

 

form:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 

execute:

<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
} else{
    echo "Problem uploading file!";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/159551-solved-image-upload/
Share on other sites

Try this:

 

<?php

//firstly - you'll want to make sure that the file is actually after being uploaded 
//its a security issue 
if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])){

$target_path = "uploads/";

//is your target path a directory?
if(is_dir($target_path){

	//I've never needed to use basename() before.
	$target_path = $target_path.$_FILES['uploadedfile']['name'];

	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
		echo 'File uploaded to '.$target_path;
	} 
	else{
		echo "Problem uploading file! Check your directories file permissions!";
	}
}
//not a directory
else{
	echo $target_path." was not found to be a directory.";
}
}
//not an uploaded file
else{
echo 'No file uploaded';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/159551-solved-image-upload/#findComment-841613
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.