views:

37

answers:

3

Hi,

I've a problem with jQuery uploadify script and I didn't found any solution. I've integrated this script on my project and everything is working fine on a Windows server(localhost) but when I try to run it on an UNIX server and I/O error is risen. This only happens when I try to upload a file that already exists on uploading folder. On Windows the file is overwritten but a UNIX I get and I/O error.

Please if you have any solutions I'll be very grateful.

Here is the server side code which I think is the problem(PHP code):

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'].$_REQUEST['folder'].'/';
    $targetFile = str_replace('//', '/', $targetPath).$_FILES['Filedata']['name'];

    if (file_exists($targetFile)) unlink($targetFile);
    copy($tempFile, $targetFile);
    echo "1";
}

Best regards, Claudiu

A: 

First few things to check:

  • Which user owns the file that exists?
  • Which user owns the directory that the file is in?
  • Which user is running your PHP script?
  • What are the permissions on the file itself?
  • What are the permissions on the directory that the file is in?

The reason I ask these questions is because it may be a simple permissions problem. The user running the unlink and file create of the target file will need write access to the directory. It's possible that the user that's running the script is not the one that owns the directory or file, in which case you may have to open up the permissions a bit.

Of course, that's just conjecture on my part but that's the first thing I'd be looking for.

paxdiablo
A: 

First of all, you should use move_uploaded_file instead of a copy.

But most likely your problem is due to a permissions problem. Can you upload any file to the folder? Have you checked that the files already in the folder (those you want to overwrite) have the same permissions as a newly uploaded one? My guess would be that you copied the files to the folder using (S)FTP and that they have a different owner/permissions so you can't overwrite them.

wimvds
A: 

In addition to the possible permissions issues mentioned by paxdiablo and wimvds, also check the case of your filename & path. Unlike windows, unix filesystems are case-sensitive.

pra