Uploading Pictures

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Uploading Pictures

Post by franknu »

Creating directory to upload pictures

--------------------------------------------------------------------------------

Ok, I am trying to upload a picture here but it seems it is no collecting the picture.
it also seems that it is not finding the folder that i assign to it

any help here on how i can accomplish this thank you.

Ok I have a HTML form, where all the info is inserted and then,It will be call later.



here is the HTML form:


Code: Select all

<input type="hidden" name="MAX_FILE_SIZE" value="1000"> 
           Picture1 (Front Business)<input name="picture1" type="file">
here 's the PHP code




Code: Select all

<?php 

if ($picture1=="none") 
  { 
    echo "Problem: no file uploaded"; 
    exit; 
  } 


  $upfile = "httpdocs/images/".$picture1_name; 

  if ( !copy($picture1, $upfile)) 

  { 
    echo "Problem: Could not move file into directory"; 
    exit; 
  } 


  echo "File uploaded successfully<br><br>"; 
  $fp = fopen($upfile, "r"); 
  $contents = fread ($fp, filesize ($upfile)); 
  fclose ($fp); 

  $contents = strip_tags($contents); 
  $fp = fopen($upfile, "w"); 
  fwrite($fp, $contents); 
  fclose($fp); 

  echo "Preview of uploaded file contents:<br><hr>"; 
  echo $contents; 
  echo "<br><hr>"; 

?>
and this is that i am dispalying

Warning: Unable to open 'C:\\Documents and Settings\\HP_Owner\\Desktop\\townsfinder\\0036.jpg' for reading: No such file or directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 118
Problem: Could not move file into directory
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look at the data in $_FILES['picture1'] .. particularly of interest is the error element.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

somethings has change this is what i am gettin now


Warning: Unable to open '' for reading: No such file or directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 119
Problem: Could not move file into directory

Code: Select all

<?php
  $picture1=$_FILES['picture1']['tmp_name'];

if ($picture1=="none")
  {
    echo "Problem: no file uploaded";
    exit;
  }


  $upfile = "./httpdocs/images/".$picture1;

  if ( !copy($picture1, $upfile))

  {
    echo "Problem: Could not move file into directory";
    exit;
  }


  echo "File uploaded successfully<br><br>";
  $fp = fopen($upfile, "r");
  $contents = fread ($fp, filesize ($upfile));
  fclose ($fp);

  $contents = strip_tags($contents);
  $fp = fopen($upfile, "w");
  fwrite($fp, $contents);
  fclose($fp);

  echo "Preview of uploaded file contents:<br><hr>";
  echo $contents;
  echo "<br><hr>";

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

print_r(), var_dump() or var_export() $_FILES and post it's output please.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

I am sorry, but i dont understand. i read about them but i kinda went blank.

thank you
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

i made more changes i tried to keep it simple so here are some of the changes made

Code: Select all

<?php
  $picture1=$_FILES['picture1']['tmp_name'];

if ($picture1=="none")
  {
    echo "Problem: no file uploaded";
    exit;
  }


  $upfile = "images/$picture_name";
    print_r ($Picture1);

 print_r ($Picture1);




  echo "File uploaded successfully<br><br>";
  $fp = fopen($upfile, "r");
  $contents = fread ($fp, filesize ($upfile));
  fclose ($fp);

  $contents = strip_tags($contents);
  $fp = fopen($upfile, "w");
  fwrite($fp, $contents);
  fclose($fp);

  echo "Preview of uploaded file contents:<br><hr>";
  echo $contents;
  echo "<br><hr>";

?>
this is my display now
Warning: fopen("images/", "w") - Is a directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 131

Warning: Supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 132

Warning: Supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 133
Preview of uploaded file contents: :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

var_dump($_FILES)

Add that to your code just before or just after you use $_FILES in the last snippet you posted. It should write some data to the output. You may have to look in your page source if viewing this in a browser. It will show details about the array, $_FILES. I would like to see that here, in a post, so I can understand what the server is trying to tell you.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

array(0) { } File uploaded successfully


Warning: fopen("images/", "w") - Is a directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 133

Warning: Supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 134

Warning: Supplied argument is not a valid File-Handle resource in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 135
Preview of uploaded file contents:

Code: Select all

<?php
  $picture1=$_FILES['picture1']['tmp_name'];

  var_dump($_FILES);

if ($picture1=="none")
  {
    echo "Problem: no file uploaded";
    exit;
  }


  $upfile = "images/$picture_name";
    print_r ($Picture1);

 print_r ($Picture1);




  echo "File uploaded successfully<br><br>";
  $fp = fopen($upfile, "r");
  $contents = fread ($fp, filesize ($upfile));
  fclose ($fp);

  $contents = strip_tags($contents);
  $fp = fopen($upfile, "w");
  fwrite($fp, $contents);
  fclose($fp);

  echo "Preview of uploaded file contents:<br><hr>";
  echo $contents;
  echo "<br><hr>";

?>

this s my new display
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

now you have your answer for the warnings: there's no data in $_FILES.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

so, how do i fix that because i am sending a file to that directory?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you're using the html code you posted originally, you've effectively told php to only allow files 1000 bytes or smaller to be uploaded. Next, if you don't have the proper <form> then you'll also have issues. I'd suggest you post more of your HTML.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

Ok , the form seems to be ok now my problem now is uploading the picture this are the changes i made

Code: Select all

<?php
  $picture1=$_FILES['picture1']['tmp_name'];

  var_dump($_FILES);



  $upfile = "./images/".$picture1_name;

   print_r ($Picture1);

    if(!copy($userfile, $upfile))
    {
    echo "problem: wrong directory";

  exit;
    }



  echo "File uploaded successfully<br><br>";
  $fp = fopen($upfile, "r");

  fclose ($fp);


  $fp = fopen($upfile, "w");
  fwrite($fp);
  fclose($fp);

  echo "Preview of uploaded file contents:<br><hr>";

  echo "<br><hr>";

?>
this is what i am dispalying now

Warning: open_basedir restriction in effect. File is in wrong directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 114
problem:

How do i fix that please i am very close i think...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

Code: Select all

<?php
  $picture1=$_FILES['picture1']['tmp_name'];

  var_dump($_FILES);



  $upfile = "/httpdocs/images/".$picture1_name;

   print_r ($Picture1);

    if(!move_uploaded_file($picture1, $upfile))
    {
    echo "problem: wrong directory";

  exit;
    }



  echo "File uploaded successfully<br><br>";
  $fp = fopen($upfile, "r");

  fclose ($fp);


  $fp = fopen($upfile, "w");
  fwrite($fp);
  fclose($fp);

  echo "Preview of uploaded file contents:<br><hr>";

  echo "<br><hr>";

?>
this is what i am displaying now



array(1) { ["picture1"]=> array(4) { ["name"]=> string(16) "icon_members.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(14) "/tmp/php156mI2" ["size"]=> int(904) } }
Warning: Unable to create '/httpdocs/images/icon_members.gif': No such file or directory in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 114

Warning: Unable to move '/tmp/php156mI2' to '/httpdocs/images/icon_members.gif' in /home/httpd/vhosts/mass-ad.com/httpdocs/insert_data.php on line 114
problem: wrong directory
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a full system path.. $_SERVER['DOCUMENT_ROOT'] may help.
Post Reply