PDA

View Full Version : copying image files from local server to remote server



psikolog
09-02-2009, 07:39 AM
Hi,

The local path for my file : C:\wamp\www\noyaevofis\images\bg.GIF

The code : if (copy("C:\wamp\www\noyaevofis\images\bg.GIF", "bg.GIF")) { echo ("saved"); } else { echo ("not saved); }


This code works in local server but gives the followig error in remote server :

Warning: copy(C:\wamp\www\noyaevofis\images\bg.GIF) [function.copy]: failed to open stream: No such file or directory in ....


This is a new problem because the above code worked in various remote servers since 2005 until July 2009.

I assume that I'm missing an update.

I'll appriciate your valuable hints.

Nejat

JasonDFR
09-02-2009, 08:36 AM
Your remote server's path to the file is C:\wamp\www\noyaevofis\images\bg.GIF ? If not, that is your problem. Try logging into the remote server with an FTP client and looking for the file. Once you find it, you'll be able to see exactly what the path is.

psikolog
09-02-2009, 09:28 AM
Thank you for your reply.

The path in remote server is different.

As I mentioned before this code always worked with different remote-server-paths in various remote servers since 2005 until July 2009. I never had a path problem for these past 4 years.

The problem is that the remote server does not accept the source path as my local path anymore.

JasonDFR
09-02-2009, 09:32 AM
All I can tell you is that the path to the file you want to copy is not correct on your remote server.

When you say remote server, are you talking about a server on the web? Or a server on you local network?

psikolog
09-02-2009, 09:38 AM
Remote Server is on the web, Local Server is on my computer.

JasonDFR
09-02-2009, 10:01 AM
Well it is unlikely that your web server is using WAMP.

Thus, the directory structure on your web server is different than your local server. This means the paths to the files are different. You must know the path to the file you wish to copy and use that path when calling copy.

psikolog
09-02-2009, 10:07 AM
Thank you for giving your valuable time to me.

psikolog
09-02-2009, 10:35 AM
Maybe the following code will make the issue more clear.

The target directory "/logo" is on the remote server hosted on web and it contains a lot of files and its chmod is 777.

<?php

if (!isset($_REQUEST['logoAdres'])) {$logoAdres="";} else $logoAdres = $_REQUEST['logoAdres'] ;
if (!isset($_REQUEST['PLogo'])) {$PLogo="";} else $PLogoAdres = $_REQUEST['PLogo'] ;
if (!isset($_REQUEST['Pname'])) {$Pname="";} else $Pname = $_REQUEST['PnameAdres'] ;

?>

<form name="Fedit" method="post" enctype="multipart/form-data">

<table align="center" width="600" cellspacing="2" cellpadding="2" style="border:1px outset #ECECEC;">
<tr>
<td bordercolor="#ececec" >Logo : </td>
<td bordercolor="#ececec">
<input type="file" name="PLogo" size="70" style="font:7pt verdana;color:#003399" onchange="document.Fedit.logoAdres.value=this.value;">
<input type="hidden" name="logoAdres">
</td>
</tr>
<tr>
<td bordercolor="#ececec" >Name for Logo : </td>
<td bordercolor="#ececec"><input type="text" name="Pname" size="50" maxlength="255" style="font:7pt verdana;color:#003399"></td>
</tr>
<tr>
<td bordercolor="#ececec" align="center" colspan="2">
<input type="submit" name="action" value="Save" onmouseover="this.style.cursor='pointer';">
</td>
</tr>
</table>

</form>

<?

$action = strtolower(trim($action));

switch($action)
{ case "save" : action_update($PLogo,$Pname,$logoAdres); break; }


function action_update($PLogo,$Pname,$logoAdres)
{
if ($logoAdres !== "") {$PLogo = $logoAdres ;}

if ($PLogo !=="" )
{
chdir("./logo");
if (copy($PLogo, $Pname)) { echo ("$PLogo saved"); } else { echo ("$PLogo is not saved"); }
chdir("..");
}
}
?>

psikolog
09-02-2009, 03:04 PM
I tested this code on Yahoo server and it worked, no errors occured and every file I selected via the form from my computer (local) has been saved to the related directory on Yahoo (remote) server.

Now the conclusion :

Yahoo server's PHP Version is 4.3.11 | My remote server's PHP Version is 5.2.9

Interpretation of copy() function has been changed in 5.2.9.

Nejat

traq
09-02-2009, 04:02 PM
(here) (http://us.php.net/manual/en/function.copy.php)
5.3.0 Added context parameter for copy() function. (Sara)


All I could find. It would cause some change in functionality, but I don't think it's the cause of your problem. In fact, if you used to be able to use the code successfully with the wrong path, I would say that that was a problem with your server/setup.

psikolog
09-02-2009, 04:34 PM
Thank you for your hint.

I know php.net/copy declaration, but it doesn't give the answer I need.

I still believe in that the problem occurs because of the interpretation of version 5.2.9-1.

Here is my commitment :

Before PHP Version 5.2.9 "the source file" could be placed on local computer or on remote server (on the web) or it could be URL on the web.

The location of the source file doesn't make any difference if the server has the PHP Version older than 5.2.9. There will be no errors while uploading a file from the user's computer to the web server that the script is running on via a form enctyped as multipart/form-data.

But in version 5.2.9 the source file can only be either a URL on the web or a path on remote server (on the web). Copy() function interprets the POSTed file path as a path on the server it is running on.

I tested my script on 3 different environments :

1. on my local server (on my computer) => it worked.

2. on Yahoo server with version 4.3.11 => it worked.

3. on another server with version 5.2.9-1 => it did not work.

The job is simple :

- there is a file on the desktop of the user.

- user enters the page.

- page has a form (enctype="multipart/form-data)

- form has an input (type="file") element.

- when the user clicks the submit button the full path of the file is POSTed

- the action file runs copy() function.

This simple job gives different results depending on the PHP Version.

Let's wait and see.

Thank you again.

Nejat

JShor
09-02-2009, 04:49 PM
Is it possible that other differences exist? Did you set permissions correctly on the server? [CHMOD?]

According to:
http://us2.php.net/copy

The ONLY changes in this function were in v.4.3.0 and v.5.3.0:

5.3.0 => Added context support.
4.3.0 => Both source and dest may now be URLs if the "fopen wrappers" have been enabled. See fopen() for more details.

It's also possible that there's a server configuration problem in the server where the copy() isn;'t working - try contacting your host.

JasonDFR
09-02-2009, 04:55 PM
If your problem is only with the copy() function I can tell you for sure that the version of php does not matter.

Can you tell us what the path to the file you want to copy is on your remote(web) server. From what you have said, this is where the problem lies.

It also seems like you are using relative paths. I would caution against this, as changes you make are more likely to cause things to break.

You could for example define an APPLICATION_PATH, then base all your paths off of that. Or use the $_SERVER['DOCUMENT_ROOT'] variable so you always have an absolute path to work off of.

JasonDFR
09-02-2009, 05:02 PM
Is it possible that other differences exist? Did you set permissions correctly on the server? [CHMOD?]


He would be getting a Permission Denied error if that was the case.

JShor
09-02-2009, 05:04 PM
I don't think that's his problem. Seems more complex than something as simple as a misdirected path ...

psikolog
09-02-2009, 05:05 PM
The directory structure on my local computer and remote server are identical.

All the related directories have chmod 777.

I have been using this remote server for more than a year and this problem occured after the server's php upgraded to ver 5.2.9.1

Nothing has been changed except PHP version on recent remote server.

I have been also using this script on Yahoo server for 3 years with a php version of 4.3.1.1 and this code works on that server perfectly well.

This code also worked on another server between the years 2005 - early 2008 without any problem.

I am sure that the problem is not because of the directory / path structure.

When I posted this issue I was hoping that someone has idea about the interpretation of copy() function.

Don't worry, I still have hope.:)

Thank both of you and I'll be pleased hearing your new comments.

Nejat

JShor
09-02-2009, 05:06 PM
No, he wouldn't be getting any errors except the one he stated, here:



if ($PLogo !=="" )
{
chdir("./logo");
if (copy($PLogo, $Pname)) { echo ("$PLogo saved"); } else { echo ("$PLogo is not saved"); }
chdir("..");
}
}


Any error he gets will say $PLogo is not saved. If there's an error, the IF boolean would return FALSE, and therefore the ELSE statement would take into effect.

JShor
09-02-2009, 05:09 PM
I have been using this remote server for more than a year and this problem occured after the server's php upgraded to ver 5.2.9.1

Nothing has been changed except PHP version on recent remote server.


Hey, things happen, people make mistakes. What I'm thinking is most likely, is that whoever the server admin who upgraded the php version was, made some other crucial mistake where the file system isn't working as it should.

Either that, or the php.ini file needs to be edited to accommodate files [which in retrospect, seems more likely in this case].

Good luck.

JasonDFR
09-02-2009, 05:10 PM
Is this the error message you are getting on your remote server?

Warning: copy(C:\wamp\www\noyaevofis\images\bg.GIF) [function.copy]: failed to open stream: No such file or directory in ....

That is the error message you posted in your first post.

Is your remote server running WAMP?
Does this path exists on your remote server?
If you upload a file to this path 'C:\wamp\www\noyaevofis\images\' on your remote server, then run this:

copy('C:\wamp\www\noyaevofis\images\test.ext', 'C:\wamp\www\noyaevofis\images\test2.ext');

(replace 'test.ext' with an actual file)

What happens?

JasonDFR
09-02-2009, 05:13 PM
Hey, things happen, people make mistakes. What I'm thinking is most likely, is that whoever the server admin who upgraded the php version was, made some other crucial mistake where the file system isn't working as it should.

Either that, or the php.ini file needs to be edited to accommodate files [which in retrospect, seems more likely in this case].


What php.ini setting are you talking about?

Take a look at the error he posted in the first post and I reposted in my last post. I don't think he would be getting this error, if the file he wants to copy 1) exists, and 2) he has the path right.

psikolog
09-02-2009, 05:51 PM
Please let me clear the issue :

1. wamp server is in my local computer and I don't have any problem with my wamp server, it is working perfect.

2. my remote server is hosted in another location and this problem began after my remote server was upgraded to php ver 5.2.9-1

3. Yes, I'm getting the following error message on remote server, not on wamp :

Warning: copy(C:\wamp\www\noyaevofis\images\bg.GIF) [function.copy]: failed to open stream: No such file or directory in ....

Is there any posts I missed to reply? If so please remind me.

Thank you.

JShor
09-02-2009, 05:52 PM
There are numerous that can be causing the upload limitations: MAX_UPLOAD_SIZE, MAX_INPUT_TIME, MEMORY_LIMIT, MAX_EXECUTION_TIME, etc.

psikolog
09-02-2009, 05:56 PM
Yes, you're right, there are.

I also replaced MAX_UPLOAD_SIZE as a hidden input element on the form, but no use.

Hoping........

Nejat

JShor
09-02-2009, 06:04 PM
It's a more stable solution if you create a php.ini file, and upload it to your web server.

Here's an example for you:
http://www.reallylinux.com/docs/php.ini

JasonDFR
09-02-2009, 06:10 PM
Please let me clear the issue :

1. wamp server is in my local computer and I don't have any problem with my wamp server, it is working perfect.

2. my remote server is hosted in another location and this problem began after my remote server was upgraded to php ver 5.2.9-1

3. Yes, I'm getting the following error message on remote server, not on wamp :

Warning: copy(C:\wamp\www\noyaevofis\images\bg.GIF) [function.copy]: failed to open stream: No such file or directory in ....


This is my last reply:

If your REMOTE SERVER is NOT RUNNING WAMP, then C:\wamp\www\noyaevofis\images\bg.GIF is NOT A VALID PATH on your REMOTE SERVER and you MUST CORRECT THE PATH. That is why you are getting the NO SUCH FILE OR DIRECTORY ERROR.

It is as simple as that.

Sorry for being frustrated. I feel like I have said the same thing numerous times and you guys just aren't getting it. Maybe I'm not clear enough...

psikolog
09-02-2009, 06:13 PM
I think first of all I should talk to my host admin and renew php installation.

As far as I can see this is my only chance for the time being.

Thank you all for your support.

Nejat

JShor
09-02-2009, 06:27 PM
But he's NOT talking about his Wamp server! Wamp runs on your local machine. He's talking about the SERVER! The SERVER is the issue. His files are not uploading on the SERVER, and THEREFORE it's NOT an issue with NO SUCH FILE OR DIRECTORY.

I'm not sure why you posted that code, he's NOT having a problem with wamp.



Please let me clear the issue :

1. wamp server is in my local computer and I don't have any problem with my wamp server, it is working perfect.


No problem with wamp.



2. my remote server is hosted in another location and this problem began after my remote server was upgraded to php ver 5.2.9-1

3. Yes, I'm getting the following error message on remote server, not on wamp :


He may be getting an error on wamp, but since it's the SERVER he's concentrated on, the error on wamp is irrelevant. The focus of the issue is the SERVER

JasonDFR
09-02-2009, 06:44 PM
I can't believe I am replying again, but here it goes:

Jshor, This is a quote from the guy asking the question:



3. Yes, I'm getting the following error message on remote server, not on wamp :

Warning: copy(C:\wamp\www\noyaevofis\images\bg.GIF) [function.copy]: failed to open stream: No such file or directory in ....

The same that you just quoted, though you left the error message out of your quote. Notice how he says he is getting the above error on his REMOTE SERVER. If his remote server is not running WAMP EDIT:"and doesn't have a c:\wamp directory (although unlikely, it is possible that a server not running wamp have a wamp directory)", and for all we know might not even be a windows server, how is it possible to use this path: C:\wamp\www\noyaevofis\images\bg.GIF in a function executed by his remote server. Explain to me how that makes sense to you.

Is your remote server a windows server or linux?

This really is my last post. Good luck. If you figure it out, please post the solution.

psikolog
09-02-2009, 07:03 PM
I checked up the php installation time for my remote server (web) : May 27 2009 10:39:32

My last successful file-upload to this server on June 16 2009 22;34

Therefore server configuration does not have too much meaning any more, am I right?

On the other hand my last successful uploaded-file-path was also C:\wamp\www\noyaevofis\images\.....

The reason is that I do all my scripting in my local server (wamp), I test the scripts in my local (wamp), if everything is ok then I transfer my scripts to remote server (web) and I test the scripts once more on remote server (web).

All the scripts running on remote server (web) must be the same scripts as running on my local (wamp) server. And all the directory structure must be the same in both servers. And they are same. Otherwise I must write different scripts for each server which is meaningless.

If I eliminate the server configuraton then only one possibility remains :

The DOM and HTML5 changes affected copy() function.

Maybe this issue must be my new research topic.

Anyway, thank you all again.

Best regards.

Nejat

psikolog
09-03-2009, 08:24 AM
I solved the problem today at 10:33 GMT+3.

It has nothing to do with neither php version nor directory structure/naming.

It is because of the way that HTML5 handles the POSTed data. Depending on this change in HTML5, the copy() function is handling the source file as : "The source file of the copy() function must be the temp_name not the full path."

$recName = $_FILES['file_name']['temp_name']

This link may give a brief idea about new HTML5 and DOM specs. : http://www.mail-archive.com/whatwg@lists.whatwg.org/msg14076.html

The following final code is tested on 2 different remote servers for IE and FireFox. No errors occured, all the files POSTed were saved into the related directories in both explorers.



<?php

if (!isset($_REQUEST['PLogo'])) {$PLogo="";} else $PLogo = $_REQUEST['PLogo'] ;
if (!isset($_REQUEST['Pname'])) {$Pname="";} else $Pname = $_REQUEST['Pname'] ;
if (!isset($_REQUEST['action'])) {$action="";} else $action = $_REQUEST['action'] ;
?>
<form name="Fedit" method="post" enctype="multipart/form-data">

<table align="center" width="600" cellspacing="2" cellpadding="2" style="border:1px outset #ECECEC;">
<tr>
<td bordercolor="#ececec" class="urunkart">Logo : </td>
<td bordercolor="#ececec">
<input type="file" name="PLogo" size="70" style="font:7pt verdana;color:#003399" >
</td>
</tr>
<tr>
<td bordercolor="#ececec" class="urunkart">Name for Logo : </td>
<td bordercolor="#ececec"><input type="text" name="Pname" size="50" maxlength="255" style="font:7pt verdana;color:#003399"></td>
</tr>
<tr>
<td bordercolor="#ececec" align="center" colspan="2">
<input type="submit" name="action" value="Save" onmouseover="this.style.cursor='pointer';">
</td>
</tr>
</table>

</form>

<?

$action = strtolower(trim($action));

switch($action)
{
case"save" : action_update($PLogo,$Pname);

break;
}


function action_update($PLogo,$Pname)
{
$PLogo = $_FILES['PLogo']['tmp_name'] ;

if ($PLogo !=="" )
{
chdir("./logo");
if (copy($PLogo, $Pname)) { echo ("$PLogo saved"); } else { echo ("$PLogo is not saved"); }
chdir("..");
}
}
?>


I thank all of you for your valuable supports.

Nejat