0

Hi every one, i try to upload form field into database along with the image but i want the the image name to be in my database as a link while the image itself will be in a directory. I have use something like this code before it works i think but the problem with this code is what i dont know.Is the problem from the directory where i want to store the image as was it keeps on returning the error below

-------Sorry, there was a problem uploading your file------


the code is ststed below

--------------------image.php------------------

<form enctype="multipart/form-data" action="addimage.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

----------------addimage.php----------------------

<?php 
 
 //This is the directory where images will be saved 
 $target = "C:/Tomcat 6.0/webapps/fphp/image/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 
 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 
 
 // Connects to your Database 
 mysql_connect("localhost", "root", "root") or die(mysql_error()) ; 
 mysql_select_db("student") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>

the table is as follow

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo text);


please i need your help so that the code will work .if you have similar code that does the same thing i will appreciate .thanks for your help and concern

4
Contributors
8
Replies
12
Views
7 Years
Discussion Span
Last Post by siamsoft
0

We have tested it in local machine, it works perfect.
You may check file permission for the target folder.

0

thank you very much sir .Please how do i check the file permission on window xp. I only know that of Linux REDHAT and SUN SOLARIS.
please help me.

0

echo "The file ". basename( $_FILESuploadedfile[/B]']) or $_FILESphoto[/B]'])

Hi every one, i try to upload form field into database along with the image but i want the the image name to be in my database as a link while the image itself will be in a directory. I have use something like this code before it works i think but the problem with this code is what i dont know.Is the problem from the directory where i want to store the image as was it keeps on returning the error below

-------Sorry, there was a problem uploading your file------


the code is ststed below

--------------------image.php------------------

<form enctype="multipart/form-data" action="addimage.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

----------------addimage.php----------------------

<?php 
 
 //This is the directory where images will be saved 
 $target = "C:/Tomcat 6.0/webapps/fphp/image/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 
 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 
 
 // Connects to your Database 
 mysql_connect("localhost", "root", "root") or die(mysql_error()) ; 
 mysql_select_db("student") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>

the table is as follow

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo text);


please i need your help so that the code will work .if you have similar code that does the same thing i will appreciate .thanks for your help and concern

0

thank you very much sir .Please how do i check the file permission on window xp. I only know that of Linux REDHAT and SUN SOLARIS.
please help me.

This link will help. Nevertheless, if you will check out , it is one of the options where control panel options is there on XP.
http://superuser.com/questions/111168/file-permissions-in-windows-xp

I do not have a XP machine here. Please try to find out.

Because you are experienced in Linux, and find difficulties in windows environment. You may not give priorities on windows.

Yes - On web server - from hosting provider the file permission icons is easy to find, else please take the help of the web hosting provider.

Please take the help of the medium like google,yahoo search engines, they will help you always.

0

Good day sir ,please is it my database user am to grant the permission.
Mydatabase user is ROOTand password is ROOT.
Look at what i did , i created user account called ROOT and I now grant permission to Root but when i run the codE, IT STILLdisplays error
--------------Sorry, there was a problem uploading your file--------
so what do i do.
thanks

0

Hi There here is the solution:

<?php //This is the directory where images will be saved $target = "C:/Tomcat 6.0/webapps/fphp/image/"; $target = $target . basename( $_FILES); //This gets all the other information from the form $name=$_POST; $email=$_POST; $phone=$_POST; $pic=($_FILES); // Connects to your Database mysql_connect("localhost", "root", "root") or die(mysql_error()) ; mysql_select_db("student") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES, $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?>

<?php

//This is the directory where images will be saved
$target = "C:/download/";
$target = $target . basename( $_FILES);

//This gets all the other information from the form
$name=$_POST;
$email=$_POST;
$phone=$_POST;
$pic=($_FILES);

// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("daniweb") or die(mysql_error()) ;

$path=$target;
//Writes the information to the database
mysql_query("INSERT INTO `employees`(`employeeid`, `name`, `email`, `phone`, `photo`) VALUES (0,'$name', '$email', '$phone', '$path')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES, $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>


Hi every one, i try to upload form field into database along with the image but i want the the image name to be in my database as a link while the image itself will be in a directory. I have use something like this code before it works i think but the problem with this code is what i dont know.Is the problem from the directory where i want to store the image as was it keeps on returning the error below

-------Sorry, there was a problem uploading your file------


the code is ststed below

--------------------image.php------------------

<form enctype="multipart/form-data" action="addimage.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

----------------addimage.php----------------------

<?php 
 
 //This is the directory where images will be saved 
 $target = "C:/Tomcat 6.0/webapps/fphp/image/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 
 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 
 
 // Connects to your Database 
 mysql_connect("localhost", "root", "root") or die(mysql_error()) ; 
 mysql_select_db("student") or die(mysql_error()) ; 
 
 //Writes the information to the database 
 mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 
 
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>

the table is as follow

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo text);


please i need your help so that the code will work .if you have similar code that does the same thing i will appreciate .thanks for your help and concern

0

Thank expert, i used the code but it only insert the directory
------C:/download/----- in the database while other columns returns null ie empty. Also when i check the directory------C:/download/------
no image were uploaded am confused of what to do

0

Plz note that you need to add the fieldname [employeeid] as auto increment then it will be ok. You can try to "echo $path" to ensure that the directory name and the filename are both in the variable $path before insertion in the table employee. Make sure that you have created the folder c:\download. On my PC everything is working fine.
Try it once more and let me know.
Siamsoft

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.