I want to upload images that will be saved in a folder. That folder is inside my website folder. eg: mywebsite(website folder). myimage(image folder).

And the path of image should be saved in mysql.

I tried the following but it is giving error "path not found." This is my path:- C/wamp/www/mywebsite/myimage.

$basePath = "myimage/";
					
$image = $_FILES['image'];
$storagePath = $basePath.$image['name'];
					
if (!is_dir($basepath)) {
	echo "Base path '$basePath' does not exist";
} 
else if (file_exists($storagePath)) {
        echo "File '$storagePath' already exists";
} 
else if (!move_uploaded_file($image['tmp_name'], $storagePath)) {
	echo "Could not move file to '$storagePath'. Check read/write persmissions on the directory";
} 
else {
        $insertQuery = "INSERT INTO $tbl_name (myImage) VALUES ('".mysql_real_escape_string($image['name'])."')";
	$execute=mysql_query($insertQuery);															   					 }

Recommended Answers

All 5 Replies

Where is your input coming from?
Is the name of the file upload form image?

$image = $_FILES['image'];

does your script run in your rootdir: mywebsite or in a subdir : mywebsite/phpfiles/

Try with $_SERVER. Example below.

$basePath = $_SERVER['DOCUMENT_ROOT'] . "/mywebsite/myimage/";

i tried

$basePath = $_SERVER['DOCUMENT_ROOT'] . "/mywebsite/myimage/";

, it's saying the path does not exists.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.