Jump to content

Recommended Posts

Hi everyone!

 

I'm trying to create a form with an upload photo bit in it.

 

The photo i know, has to be saved on the server somewhere. Iv'e created an images folder both in my host's control pannel and in my dreamwever files and FTP'd it to the server. I've tried both ways of sending the test .jpg to each folder but i'm getting the desgined mySQL error.

 

What's going worng here?

 

<?php 

//This is the directory where images will be saved 
$target = "/images/COMPANIES"; 
$target = $target . basename( $_FILES['photo']['name']); 

//This gets all the other information from the form 
$company_name=$_POST['company_name']; 
$basicpackage_description=$_POST['basicpackage_description']; 
$location=$_POST['location']; 
$postcode=$_POST['postcode'];
$upload=($_FILES['photo']['name']); 

// Connects to your Database 
mysql_connect("******host", "****username", "****password") or die(mysql_error()) ; 
mysql_select_db("****DB") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; 

//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."; 
} 
?> 

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/
Share on other sites

just add, after turning error reporting on the following error message(s) are displayed:

 

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 5

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 12

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 22

Sorry, there was a problem uploading your file.

Parameters

 

 

expression

 

The expression to be printed.

 

return

 

If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to TRUE, print_r() will return the information rather than print it.

 

Scootstah, adding that in my script returns this:

 

"Array

(

    [upload] => Array

        (

            [name] => Zodiac_Sign_Tattoo___Aquarius_by_MPtribe.jpg

            [type] => image/jpeg

            [tmp_name] => /tmp/phpfXyUCg

            [error] => 0

            => 26389

        )

 

)

 

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 9

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 16

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26

Sorry, there was a problem uploading your file. "

 

 

The form code is this:

 

<form enctype="multipart/form-data" action="basicpackage-send.php" method="POST">

Compnany Name:<br /> <input type="text" name="company_name"><br>

Company Description:<br /> <input type="text" name = "basicpackage_description"><br>

Location:<br /> <input type="text" name = "location"><br>

Postcode:<br /> <input type="text" name = "postcode"><br>

Company Logo/Photo:<br /> <input type="file" name="upload"><br>

<input type="submit" value="Add">

</form>

 

Thanks

update from my host's tech support:

 

"

 

 

Hello,

 

Thank you for contacting Support.

 

On our platform, root is the home directory path. You can upload the image files into the root directory of your account. If you are using any script, then you can use the home directory path: /home/users/web/b109/ipg.removalspacecom .

 

Thank you!

 

Sincerely,

 

Lakeshia Sidwick

Customer Support"

 

is this the path i need to put in my script for the images to go to or not? do i create a folder here?

 

In your form you are using

<input type="file" name="upload">

So "upload" is the name you're using.

In processing, you need to use this same name.

<?php 

//This is the directory where images will be saved 
$target = "/images/COMPANIES/"; 
$filename = stripslashes($_FILES['upload']['name']);
$target = $target.$filename; 

//This gets all the other information from the form 
$company_name=$_POST['company_name']; 
$basicpackage_description=$_POST['basicpackage_description']; 
$location=$_POST['location']; 
$postcode=$_POST['postcode'];
$upload=$filename; 

// Connects to your Database 
mysql_connect("******host", "****username", "****password") or die(mysql_error()) ; 
mysql_select_db("****DB") or die(mysql_error()) ; 

//Writes the information to the database
$company_name = mysql_real_escape_string($company_name);
$basicpackage_description = mysql_real_escape_string($basicpackage_description);
$location = mysql_real_escape_string($location);
$postcode = mysql_real_escape_string($postcode);
$upload = mysql_real_escape_string($upload); 
mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". $_FILES['upload']['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."; 
} 
?>

 

 

thank you for that help.

 

where does this "upload" photo/picture go to?

 

After just testing out the new code i'm getting these error messages:

 

"Array

(

    [upload] => Array

        (

            [name] => 360mainhead.jpg

            [type] => image/jpeg

            [tmp_name] => /tmp/phpINBhZP

            [error] => 0

            => 15625

        )

 

)

 

 

Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 16

 

Warning: move_uploaded_file(/home/users/web/b109/ipg.removalspacecom360mainhead.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpINBhZP' to '/home/users/web/b109/ipg.removalspacecom360mainhead.jpg' in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26

Sorry, there was a problem uploading your file."

 

 

 

It looks like it's having trouble sending it to the server but i have permissions to do this as i've contacted my host's tech support to clear it up? i'm told it just goes to the root directory of my server.

there was a 'photo' on line 16 but i changed that now to 'upload'

 

the error messages are these:

 

"Array

(

    [upload] => Array

        (

            [name] => 360mainhead.jpg

            [type] => image/jpeg

            [tmp_name] => /tmp/phpe1KDpI

            [error] => 0

            => 15625

        )

 

)

 

 

Warning: move_uploaded_file(/home/users/web/b109/ipg.removalspacecom360mainhead.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpe1KDpI' to '/home/users/web/b109/ipg.removalspacecom360mainhead.jpg' in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26

Sorry, there was a problem uploading your file."

 

how do i change permissions?

Is the folder(directory) 'images' in you base folder?  Meaning MyDomain.com/images

 

Or is the "path" relative to the processing file?

 

If relative try

 

$target = "images/COMPANIES/";

$filename = stripslashes($_FILES['upload']['name']);

$target = $target.$filename;

the folder is in my filemanger on my host's control panel, i thought that's where it had to be sent?

 

I've selected topic not solved as now the other varibales of my form are not being upadted in mySQL? but the image is being sent to the folder just fine???

 

here's the form code again:

 

<form enctype="multipart/form-data" action="basicpackage-send.php" method="POST"> 
Compnany Name:<br /> <input type="text" name="company_name" id="company_name"><br> 
Company Description:<br /> <input type="text" name = "basicpackage_description" id="basicpackage_description"><br> 
Location:<br /> <input type="text" name = "location" id="location"><br> 
Postcode:<br /> <input type="text" name = "postcode" id="postcode"><br>
Company Logo/Photo:<br /> <input type="file" name="upload" id="upload"><br> 
<input type="submit" value="Add"> 
</form>

 

php code:

 

<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo '<pre>' . print_r($_FILES, true) . '</pre>';


//This is the directory where images will be saved 
$target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; 
$target = $target . basename( $_FILES['upload']['name']); 

//This gets all the other information from the form 
$company_name=$_POST['company_name']; 
$basicpackage_description=$_POST['basicpackage_description']; 
$location=$_POST['location']; 
$postcode=$_POST['postcode'];
$upload=($_FILES['upload']['name']); 

// Connects to your Database 
mysql_connect("host", "username", "password") or die(mysql_error()) ; 
mysql_select_db("DBname") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". basename( $_FILES['upload']['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."; 
} 
?> 

 

Before the upload bit was created, the other parts of the form went straight in to mySQL on testing??

More than likely INSERT is failing because $target is not escaped.

<?php 
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo '<pre>' . print_r($_FILES, true) . '</pre>';


//This is the directory where images will be saved 
$target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; 
$target = $target . basename( $_FILES['upload']['name']); 

//This gets all the other information from the form 
$company_name=$_POST['company_name']; 
$basicpackage_description=$_POST['basicpackage_description']; 
$location=$_POST['location']; 
$postcode=$_POST['postcode'];
$upload=($_FILES['upload']['name']); 

// Connects to your Database 
mysql_connect("host", "username", "password") or die(mysql_error()) ; 
mysql_select_db("DBname") or die(mysql_error()) ; 


//Writes the photo to the server 
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory";

$company_name = mysql_real_escape_string($company_name);
$basicpackage_description = mysql_real_escape_string($basicpackage_description);
$location = mysql_real_escape_string($location);
$postcode = mysql_real_escape_string($postcode);
$upload = mysql_real_escape_string($upload); 

//Writes the information to the database 
mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") or die(mysql_error()); 
} 
else { 

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

The echoed error is this:

 

Array

(

    [upload] => Array

        (

            [name] => 360mainhead.jpg

            [type] => image/jpeg

            [tmp_name] => /tmp/php4eoXyy

            [error] => 0

            => 15625

        )

 

)

 

Column count doesn't match value count at row 1The file 360mainhead.jpg has been uploaded, and your information has been added to the directory

 

 

 

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.