Forum Moderators: coopster

Message Too Old, No Replies

File Copy Error

failed to open stream error

         

ymasood

9:41 am on Jul 30, 2005 (gmt 0)

10+ Year Member



Hi All, my first time at the forums and look forward to learning and contributing to my best. Here's a piece of code I'm running on my server though I keep getting the following error. I'm not too sure what might be the issue, however, I have the permissions set properly - though I doubt if I'm using the right folder paths. Cheers and regards, YM.

The Code:

<?php
if (isset($_POST['cmdsave'])){
$db_connection='aht';
$con_table = 'brand';
if(!isset($_POST['filelogo'])){$_POST['filelogo'] = '';}
$fileinput = stripslashes($_POST['filelogo']);
$redirect_url = 'view.php';
if(!empty($_POST['filelogo']))
{
$fileext=strstr(basename($fileinput),".");
$filename= $_POST['id'] . "_$con_table" . $fileext;

$query2="UPDATE $con_table SET logo='$filename' where id=". $_POST['id'] ."";

$result2=mysql_query($query2);

if(!copy($fileinput, "/httpdocs/images/brand_images/$filename")) die("Can't copy $fileinput to $filename");
}
if ($redirect_url <> ''){
header("Location: " . $redirect_url); }
}
?>

The Error:

Warning: copy(C:\Documents and Settings\ym\Desktop\picture.gif): failed to open stream: No such file or directory in /home/httpd/vhosts/aht/httpdocs/admin/brand/edit.php on line 69
Can't copy C:\Documents and Settings\ym\Desktop\picture.gif to 10_brand.gif

dreamcatcher

10:02 am on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World ymasood :)

The clue is in the error message. 'No such file or directory in...'

Looks like your path is wrong to the directory you are copying to. Check your paths.

dc

ymasood

10:27 am on Jul 30, 2005 (gmt 0)

10+ Year Member



Dear Dreamcatcher, many thanks to you! I'm sure the paths have the issue however, I'm unable to figure out if the path should be the physical path or the URL path? YM

ymasood

11:09 am on Jul 30, 2005 (gmt 0)

10+ Year Member



Doesn't see to work yet. The file with the form is httpdocs/admin/brand/edit.php while one of the paths I tried to copy to is ../../images/brands/ since the site structure is:

root
admin
brand
images
brands
edit.php

Help needed! Looks like something simple has stuck. YM

jatar_k

3:03 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



physical path should work and you should use the full path from server root if you can

it looks like the path would be

/home/httpd/vhosts/aht/httpdocs/images/brands/

dreamcatcher

3:36 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What jatar_k posted will work, or try simply:

if(!copy($fileinput, "images/brand_images/$filename")) die("Can't copy $fileinput to $filename");

dc

ymasood

7:50 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



Dear All,

Whew, what a day - been at this almost endlessly and finally reduced all stuff to the following since my brain couldn't take any more - here's the simplified stuff:

The form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form action="upload_file_script.php" method="post" enctype="application/x-www-form-urlencoded" name="upload_file" id="upload_file">
<input name="upload_file" type="file" id="upload_file">
<input name="submit" type="submit" id="submit" value="Submit">
</form>
</body>
</html>

The Script:

<?php
$fileinput = $_POST['upload_file']; //confusion
$filename=basename($fileinput);

if(is_uploaded_file($_POST['upload_file']))
{
echo "The file name is: " . $filename;
} else
{
echo "There seems to be an issue. The file is not uploaded via HTTP Post.";
}

//if(!copy($fileinput,"/images/$filename")) die("Can't copy $fileinput to $filename");
?>

I've commented the last line since the operation still keeps failing and one more thing, the is_uploaded_file keeps returning false be it any of the two EncTypes, application/x-www-form-urlencoded or multipart/form data - which one is used actually?

Finally, found this on the web:

[bugs.php.net...]

...and it might seem this would be the case, however, I'm not too sure - so I posted this entire query to my host also.

I hope I get to the bottom of this. Any help!

Rgds,

YM