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
Post
by franknu » Tue Jul 04, 2006 8:08 am
I need help please. I've trying to do this for weeks by far has been the most diffult task i been tring to do in PHP.
It seems that the file goes up fine, but i cant move it to the directory..
i want to move the file up to a folder call images
and this is where it is
httpdocs
images
all files down here
here is the PHP Codes
Code: Select all
<?php
print(htmlspecialchars(dirname(__FILE__))."<br>");
$picture1=$_FILES['picture1']['tmp_name'];
var_dump($_FILES);
print_r ($Picture1);
$picture1_name = $_FILES['picture1']['name']; //Or any other file name, i.e. "123.jpg"
$cur_folder = dirname(__FILE__);
$upfile = $cur_folder.'home/httpdoc/images'.$picture1_name;
$path_parts = pathinfo('/www/mass-ad.com/images');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
if(!move_uploaded_file($picture1, $upfile))
{
echo "problem: could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
?>
here is what i am displaying..
Code: Select all
/home/httpd/vhosts/mass-ad.com/httpdocs
array(1) { ["picture1"]=> array(4) { ["name"]=> string(15) "tomato-puff.jpg" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(4) "none" ["size"]=> int(0) } } /www/mass-ad.com images com/images problem: could not move file into directory
Please help
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Jul 04, 2006 8:13 am
have you echo'd $upfile to see if it is a valid directory?
try also using:
Code: Select all
$upfile = realpath($cur_folder.'home/httpdoc/images'.$picture1_name);
Though it looks like you are missing a '/' at the end of images, so it should read:
Code: Select all
$upfile = realpath($cur_folder.'home/httpdoc/images/'.$picture1_name);
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Tue Jul 04, 2006 8:25 am
this is what i am displaying now
Code: Select all
/home/httpd/vhosts/mass-ad.com/httpdocs
array(1) { ["picture1"]=> array(4) { ["name"]=> string(15) "tomato-puff.jpg" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(4) "none" ["size"]=> int(0) } }
/home/httpd/vhosts/mass-ad.com/httpdocshome/httpdoc/imagestomato-puff.jpg
/www/mass-ad.com images com/images problem: could not move file into directory
this are the changes i made
Code: Select all
<?php
print(htmlspecialchars(dirname(__FILE__))."<br>");
$picture1=$_FILES['picture1']['tmp_name'];
var_dump($_FILES);
print_r ($Picture1);
$picture1_name = $_FILES['picture1']['name']; //Or any other file name, i.e. "123.jpg"
$cur_folder = dirname(__FILE__);
$upfile = $cur_folder.'home/httpdoc/images'.$picture1_name;
echo"<br>";
echo"$upfile";
echo"<br>";
$path_parts = pathinfo('/www/mass-ad.com/images');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
$upfile = realpath($cur_folder.'home/httpdoc/images/'.$picture1_name);
if(!move_uploaded_file($picture1, $upfile))
{
echo "problem: could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
?>
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Jul 04, 2006 8:28 am
did you read it?
Code: Select all
/home/httpd/vhosts/mass-ad.com/httpdocshome/httpdoc/imagestomato-puff.jpg
imagestomato-puff.jpg?
Also my previous reply has an error, change to:
Code: Select all
$upfile = realpath($cur_folder.'home/httpdoc/images/') . $picture1_name;
//add this for debug purposes
var_dump($upfile);
die;
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Tue Jul 04, 2006 8:47 am
ok, this is defenely the closes i been. but now i dont see the file on the folder images. it seems it went in but it is no checking for errors ither
Code: Select all
<?php
print(htmlspecialchars(dirname(__FILE__))."<br>");
$picture1=$_FILES['picture1']['tmp_name'];
var_dump($_FILES);
print_r ($Picture1);
$picture1_name = $_FILES['picture1']['name']; //Or any other file name, i.e. "123.jpg"
$cur_folder = dirname(__FILE__);
$upfile = realpath($cur_folder.'home/httpdoc/images/') . $picture1_name;
//add this for debug purposes
var_dump($upfile);
die;
if(!move_uploaded_file($picture1, $upfile))
{
echo "problem: could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
?>
displaying
Code: Select all
/home/httpd/vhosts/mass-ad.com/httpdocs
array(1) { ["picture1"]=> array(4) { ["name"]=> string(8) "0036.jpg" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(4) "none" ["size"]=> int(0) } } string(8) "0036.jpg"
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Jul 04, 2006 9:27 am
ok, try this:
Code: Select all
<?php
print(htmlspecialchars(dirname(__FILE__))."<br>");
$picture1=$_FILES['picture1']['tmp_name'];
var_dump($_FILES);
print_r ($Picture1);
$picture1_name = $_FILES['picture1']['name']; //Or any other file name, i.e. "123.jpg"
$cur_folder = dirname(__FILE__);
$upfile = realpath($cur_folder.'home/httpdoc/images/') //. $picture1_name;
//add this for debug purposes
var_dump($upfile);
die;
if(!move_uploaded_file($picture1, $upfile))
{
echo "problem: could not move file into directory";
exit;
}
echo "File uploaded successfully<br><br>";
?>If at the end, it displays
bool(false) where it currently displays
string(8) "0036.jpg" that means the directory given to realpath() does not exist.
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Tue Jul 04, 2006 10:19 am
ok, i did that and i am still getting the same message.
i dont know what to do next .
i guess so still sit still and cry
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Tue Jul 04, 2006 10:21 am
Code: Select all
/home/httpd/vhosts/mass-ad.com/httpdocs
array(1) { ["picture1"]=> array(4) { ["name"]=> string(14) "p_icon_mem.gif" ["type"]=> string(9) "image/gif" ["tmp_name"]=> string(4) "none" ["size"]=> int(0) } } string(14) "p_icon_mem.gif" problem: could not move file into directory
franknu
Forum Contributor
Posts: 146 Joined: Sun May 28, 2006 9:29 am
Post
by franknu » Tue Jul 04, 2006 12:26 pm
i found some new codes online which seem to work better
but i still have problems
Code: Select all
<?php
print(htmlspecialchars(dirname(__FILE__))."<br>");
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
if(!empty($HTTP_POST_FILES["picture1"]))
{
$uploaddir = realpath("/httpdocs/images/");
var_dump($uploaddir);
if (move_uploaded_file($HTTP_POST_FILES["picture1"]["tmp_name"], $uploaddir . $HTTP_POST_FILES["picture1"]["name"])) {
echo("file uploaded");
} else {
echo ("error!");
}
}
?>
my displaying
/home/httpd/vhosts/mass-ad.com/httpdocs
bool(false) error!