Page 1 of 2
Uploading Pictures
Posted: Fri Jun 23, 2006 6:45 pm
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
Posted: Fri Jun 23, 2006 6:56 pm
by feyd
look at the data in $_FILES['picture1'] .. particularly of interest is the error element.
Posted: Fri Jun 23, 2006 8:13 pm
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>";
?>
Posted: Fri Jun 23, 2006 8:27 pm
by feyd
print_r(),
var_dump() or
var_export() $_FILES and post it's output please.
Posted: Fri Jun 23, 2006 8:42 pm
by franknu
I am sorry, but i dont understand. i read about them but i kinda went blank.
thank you
Posted: Fri Jun 23, 2006 8:49 pm
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:

Posted: Fri Jun 23, 2006 8:51 pm
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.
Posted: Sat Jun 24, 2006 8:47 am
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
Posted: Sat Jun 24, 2006 9:31 am
by feyd
now you have your answer for the warnings: there's no data in $_FILES.
Posted: Sat Jun 24, 2006 11:10 am
by franknu
so, how do i fix that because i am sending a file to that directory?
Posted: Sat Jun 24, 2006 5:50 pm
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.
Posted: Sun Jun 25, 2006 7:47 pm
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...
Posted: Sun Jun 25, 2006 8:03 pm
by feyd
Posted: Sun Jun 25, 2006 8:08 pm
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
Posted: Sun Jun 25, 2006 8:12 pm
by feyd
use a full system path.. $_SERVER['DOCUMENT_ROOT'] may help.