php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #10835 File Upload
Submitted: 2001-05-12 19:19 UTC Modified: 2002-07-02 14:27 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: fergiboy at home dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: ANY OS: ANY
Private report: No CVE-ID: None
 [2001-05-12 19:19 UTC] fergiboy at home dot com
I created an upload script that will upload to my ftp server, the variable $file comes from a different file:
$a = stripslashes ($file);
$b = basename ($a);
$ftp_server = "ftp_server";
$ftp_user_name = "user";
$ftp_user_pass = "password";
$dir = "ftp";
$conn_id = ftp_connect("$ftp_server"); 
$login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass"); 
$cd = ftp_chdir ($conn_id, $dir);
$upload = ftp_put($conn_id, $b, $a, FTP_BINARY); 
if (!$upload) { 
        echo "<b>Ftp upload has failed!</b><br>";
    } else {
        echo "Uploaded<br>";
    }
$discon = ftp_quit($conn_id); 
echo "<i>$b</i>";

This script will work most of the time, but when the file to be uploaded is located in certain folders the file will not upload.

I made one change to the php.ini file to allow uploads greater than 2 megs.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-12 19:45 UTC] fergiboy at home dot com
an example:
$file = C:\\whatever.doc
that whould make 
$a = C:\whatever.doc
that would make
$b = whatever.doc

The file will upload from C:\ but will not upload from the desktop.
 [2001-05-12 20:04 UTC] derick@php.net
Hello,

can you try if this has anything to do with spaces in filenames?
(so try "C:\\Te st.doc").

If that's the case you need to escape your filename like this:
 $b = strreplace (" ", "\ ", $b);
 [2001-05-12 22:24 UTC] fergiboy at home dot com
I added an echo $a and an echo $b.  I also some debug code to see if it was connection to the ftp server. The output is:
C:\Te st.doc
Te st.doc
Connected
Ftp upload has failed!

So 
$a=C:\Te st.doc
$b=Te st.doc
So it should upload the file as fallows:
$upload = ftp_put($conn_id, "C:\Te st.doc", "Te st.doc", FTP_BINARY); 

I added the code:
$b = str_replace (" ", "\ ", $b);
to no avail :(
 [2002-02-14 03:55 UTC] ksp at ideafix dot org
I have got a similar error with the ftp_chdir function.
I can't change to a directory with spaces in it , nor making the strings replacement shown here... 
I'm using:
Php server: W2k Server(no SP), Apache 1.3 , Php 4.0.5
ftp server: W2k Professional SP2, ftp of IIS, access anonymous.

Thanks in advance.
 [2002-02-15 12:04 UTC] ksp at ideafix dot org
I've found the problem.
The ftp from IIS is configured to handle the "Directory Style" as "MSDOS"...... you only have to change it to "UNIX" for php's ftp functions work properly and handle spaces in paths and names.

Greetings
 [2002-02-15 14:32 UTC] fergiboy at home dot com
Thanks for your help.
 [2002-04-03 02:50 UTC] yohgaki@php.net
There are so meny dir listing styles...
(Imagine how many locales we have...)

I think it will not be fixed anytime soon.
We need to document this limitation for now.

 [2002-07-02 14:27 UTC] jan@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2003-11-11 17:21 UTC] mdstyers at yahoo dot com
I am trying to run this script in IE6 on an XP machine.  The server is UNIX.  For some reason I can not get a file from my local machine to upload to the server.

Any ideas?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 07:01:29 2024 UTC