0

i can upload to MYSQL, with user generated content, picture included...

when i access the information, everything appears but the picture, just the pictures file name is listed (no pic)

is my code wrong?... am i missing something?
would appreciate any help

define(`uploadpath`, `htdocs/phpsessions/images`);


{  

 
$pix=$_FILES['pix']['name'];
$target=uploadpath . $pix;
echo"$target";
if(move_uploaded_file($pix, $target)){
// do your coding here to give a thanks message or any other thing. 
}else{echo "Failed to upload file Contact Site admin to fix the problem";}






    $user="user";
    $host="website";
    $passwd="password";
    $dbname="alpha";
     $cxn = mysql_connect('website', 'user', 'passord'); if (!$cxn) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(alpha); 
    $sql = "INSERT INTO details (`classificationss`,`condition`,`type`,`price`,`region`,`size`,`comment`,`pix`) VALUES ('$classificationss', '$condition','$type','$price','$region','$size','$comment','$pix')";
    $result = mysql_query($sql,$cxn)
               or die("Couldn't execute ? query: " . mysql_error()); 

                   $_SESSION['auth']="yes";                          
                   $_SESSION['logname'] = $loginName;    
                     
      
        header("Location: New_member.php");               

     
          } 
  break;                                                

default:                                              
    include("login_form2.inc");


  /*end of thing3*/


}  
?>
<? ob_flush(); ?>

Edited by Narue: Added code tags

3
Contributors
14
Replies
16
Views
5 Years
Discussion Span
Last Post by ronysios
0
$pix=$_FILES['pix']['name'];
$target=uploadpath . $pix;
echo"$target";
if(move_uploaded_file($pix, $target)){

shouldn't that be:

$pix=$_FILES['pix']['name'];
$pixtmp = $_FILES['pix']['tmp_name'];
$target=uploadpath . $pix;
echo"$target";
if(move_uploaded_file($pixtmp, $target)){
0

thank you, i tried your script change, but unfortunately my pix still do not "move" to the "images" folder where my html docs are located..when i call up the data everything appears, but the pix, which is represented by its filename. as indicated below...

pneus new winter 0-50 Abitibi-Tamiscamingue P1558013 work photo.JPG ..


can it be related to this?

define('uploadpath', 'root/htdocs/phpsessions/images');

i am completely lost..:(

0

try making the upload path relative to the script itself.
e.g. if the script is in "/includes/", and if your upload directory is "/images/", you could do this:

define('uploadpath', '../images/');

If you really have to use root:

define('uploadpath', $_SERVER['DOCUMENT_ROOT'] . "/images/");

then that shoulkd work fine when you:

$target=uploadpath . $pix;
0

first off i would like to thank you again for your help...
unfortunately im getting the results however i did add this script to see if i successfully transfer and

define('uploadpath', $_SERVER . "/images/");

$pix=$_FILES;
$pixtmp = $_FILES;
$target=uploadpath . $pix;
echo "$target";
if(move_uploaded_file($pixtmp, $target)){

echo "File is valid, and was successfully moved.\n";
} else {
echo "not moved";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

which loads with page, don't know if this code is helping or hindering, however, when i "SELECT" from database, it still only gives me the filename, and the image is not in my "images" folder..

home/users/web/b2947/pow.xyz/htdocs/images/not uploaded Here is some more debugging info:Array ( )

if you need more code i would be more than happy
thanks ron

Edited by ronysios: n/a

0

Are you saving the upload path to the database and trying to use that path to display the image?

0

Are you saving the upload path to the database and trying to use that path to display the image?

thanks for responding, i hope this is what you were asking..

the image gets successfully uploaded into mysql...everything i have read says i have to move that image from its temporary folder within the server root to where my html documents reside, where i created a folder called "images"

im not anywhere near the novice level of code writing(re:super beginner), i understand the point my book makes..however, for me, if the code was actually moved the picture file from the temporary folder to the "images" folder successfully, the picture should actually be in that folder?...

0

I don't know what you mean by "the image gets successfully uploaded into mysql" as images aren't saved into the database.

Anyway this is the code I use to move uploaded files from the temporary folder into your designated folder:

$name = basename($_FILES['image']['name']);
$NEW_IMAGE_PATH = "/images/" . $name;

move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);

I havent tested this actual script but something along these lines should do the trick.

0

I don't know what you mean by "the image gets successfully uploaded into mysql" as images aren't saved into the database.

Anyway this is the code I use to move uploaded files from the temporary folder into your designated folder:

$name = basename($_FILES['image']['name']);
$NEW_IMAGE_PATH = "/images/" . $name;

move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);

I havent tested this actual script but something along these lines should do the trick.

hi,
what i mean is that when i "browse" my database within the mysql environment, the file name, in this case, photo.jpg, is listed...my understanding is that the actual picture is in a temporary folder on the server..the book i have, says i then have to transfer that photo from that temp. folder to a folder where my htdocs are located..sounds simple enough..but..there's always but..when i try and "select" through another php doc, i get all the information posted with the picture and only picture name "photo.jpg".no picture, when i check my images folder, no image is present....

becasue i am sometimes dumber than a bag of hammers, can you verify if i made the proper adjustments to your code

$pix = basename($_FILES);
$NEW_IMAGE_PATH = "/images/" . $pix;
move_uploaded_file($_FILES, $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);

$name = basename($_FILES);
$NEW_IMAGE_PATH = "/images/" . $name;
move_uploaded_file($_FILES, $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);


thanks again

0

hi,
what i mean is that when i "browse" my database within the mysql environment, the file name, in this case, photo.jpg, is listed...my understanding is that the actual picture is in a temporary folder on the server..the book i have, says i then have to transfer that photo from that temp. folder to a folder where my htdocs are located..sounds simple enough..but..there's always but..when i try and "select" through another php doc, i get all the information posted with the picture and only picture name "photo.jpg".no picture, when i check my images folder, no image is present....

becasue i am sometimes dumber than a bag of hammers, can you verify if i made the proper adjustments to your code

$pix = basename($_FILES);
$NEW_IMAGE_PATH = "/images/" . $pix;
move_uploaded_file($_FILES, $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);

$name = basename($_FILES);
$NEW_IMAGE_PATH = "/images/" . $name;
move_uploaded_file($_FILES, $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);


thanks again

upon loading the page i got this

Warning: chmod() [function.chmod]: No such file or directory


help

0

When a file is uploaded it goes into a temporary folder only while the script is processing. As soon as the script has stopped working the file is deleted, so the file must be moved immediately after the upload before the end of the script.

This code should be placed after the upload script, but before it is inserted into the MYSQL database...

$name = basename($_FILES['pix']['name']); //GETS THE IMAGE NAME. 'PIX' SHOULD BE THE NAME OF THE UPLOAD INPUT BOX, E.G <input type="file" name="pix">
$NEW_IMAGE_PATH = "/images/" . $name; //SETS THE DIRECTORY YOU WANT THE IMAGE MOVING TO
move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH); //MOVES THE FILE
chmod($NEW_IMAGE_PATH, 0777); //MAKES SURE THE IMAGE HAS THE CORRECT PERMISSIONS

Edited by toms ace: n/a

0

When a file is uploaded it goes into a temporary folder only while the script is processing. As soon as the script has stopped working the file is deleted, so the file must be moved immediately after the upload before the end of the script.

This code should be placed after the upload script, but before it is inserted into the MYSQL database...

$name = basename($_FILES['pix']['name']); //GETS THE IMAGE NAME. 'PIX' SHOULD BE THE NAME OF THE UPLOAD INPUT BOX, E.G <input type="file" name="pix">
$NEW_IMAGE_PATH = "/images/" . $name; //SETS THE DIRECTORY YOU WANT THE IMAGE MOVING TO
move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH); //MOVES THE FILE
chmod($NEW_IMAGE_PATH, 0777); //MAKES SURE THE IMAGE HAS THE CORRECT PERMISSIONS

thanks for the quick response..i copied my code maybe it will help, i think i have it in the right location???

<? ob_start(); ?>
<?php
/* Program: upload.php
 * Desc:    to sell
 *          (1) stuff 
 *          (2) stuff. 
 */

define('uploadpath', $_SERVER['DOCUMENT_ROOT'] . "/images/");





$pix = basename($_FILES['pix']['name']);
$NEW_IMAGE_PATH = "/images/" . $pix; 
move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH);
chmod($NEW_IMAGE_PATH, 0777);




session_start();                                          
switch (@$_POST['Button'])                                
{

/*thing1*/
  case "Register":                                      
   /* Check for blanks */
    foreach($_POST as $field => $value)                  
    {
      if($field != "comments")                                 
      {
        if(empty($value))
        {
          $blanks[] = $field;
        }
        else
        {
          $good_data[$field] = strip_tags(trim($value));
        }
      }
    }   
/*end of thing1*/
                                                 
                                                       


/*thing2*/
  /* validate data */
    foreach($_POST as $field => $value)                  
    {
      if(!empty($value))                                 
      {
        if(preg_match("/classificationss/i",$field)or
          preg_match("/condition/i",$field)or 
          preg_match("/type/i",$field)or
           preg_match("/price/i",$field) or 
           preg_match("/region/i",$field) or
           preg_match("/size/i",$field) or
           preg_match("/comment/i",$field) or
           preg_match("/pix/i",$field))
        {
          if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/", 
                          $value))
          {
            $errors[] = "$value say what is not  valid.";
          }
        }


              } // end if not empty                             
    } 
    foreach($_POST as $field => $value)                 
    {
      $$field = strip_tags(trim($value));
    }
    if(@is_array($errors))                              
    { 
      $message_2 = "";
      foreach($errors as $value)
      {
        $message_2 .= $value." Please try again<br />";
      }
      include("login_form2.inc");
      exit();
    } 
// end if errors are found                        
/*end of thing2*/

 
                 

/*thing3*/
    {  
 
    $user="xxx";
    $host="rrr.powwebmysql.com";
    $passwd="yyy";
    $dbname="alpha";
        $cxn = mysql_connect('rrr.powwebmysql.com', 'xxx', 'yyy'); if (!$cxn) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(alpha); 
    $sql = "INSERT INTO details (`classificationss`,`condition`,`type`,`price`,`region`,`size`,`comment`,`pix`) VALUES ('$classificationss', '$condition','$type','$price','$region','$size','$comment','$pix')";
    $result = mysql_query($sql,$cxn)
               or die("Couldn't execute ? query: " . mysql_error()); 

    
               $_SESSION['auth']="yes";                          
      $_SESSION['logname'] = $loginName;    
                     
      /* send email to new Customer */

 
        header("Location: New_member.php");               


      $emess = "You have successfully registered. ";
      $emess .= "Your new user name and password are: ";
      $emess .= "\n\n\t$loginName\n\t";
      $emess .= "$password\n\n";
      $emess .= "We appreciate your interest. \n\n";
      $emess .= "If you have any questions or problems,";
      $emess .= " email outerbanx13@yahoo.com";          
      $subj = "Your new customer registration";         
     # $mailsend=mail("$email","$subj","$emess");       
     
          } 
  break;                                                

  default:                                              
    include("login_form2.inc");
/*end of thing3*/

}  
?>
<? ob_flush(); ?>

chmod($NEW_IMAGE_PATH, 0777);
my permissions is 644, would that make a difference

0

Thats seems like the right place to me, does the script work like that?

I usually use 777 but try 644 if you prefer it, see how it goes. PHP is all about trial and error. Very frustrating sometimes haha.

0

Thats seems like the right place to me, does the script work like that?

I usually use 777 but try 644 if you prefer it, see how it goes. PHP is all about trial and error. Very frustrating sometimes haha.

i will try tomorrow...new day maybe ill see the trees from the forest..ill keep you posted thanks

0

upon loading the page i got this

Warning: chmod() [function.chmod]: No such file or directory


help

define('NEW_IMAGE_PATH', $_SERVER['DOCUMENT_ROOT'] . "/images/");



$pix = basename($_FILES['pix']['name']);
$NEW_IMAGE_PATH = "/images/" . $pix; 
move_uploaded_file($_FILES['image']['tmp_name'], $NEW_IMAGE_PATH);

chmod($NEW_IMAGE_PATH, 0644);


Warning: chmod() [function.chmod]: No such file or directory


im just wondering what would i do to define chmod...my web concierge says i have to define this..as he eloquently wrote

"First of all there is no temp file on your site. And, the error I see is a warning of that the chmod command is not recognized. Which could mean that the $NEW_IMAGE_PATH may not be defined properly in your php"


i think with your help i am close to resolving, kinda seeing the light at the end of the tunnel, just hope it is not another train...

Edited by peter_budo: Keep It Clear - Do use code tags when posting any code

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.