i have a script which works as i were using it in localhost(wampserver),for uploading photo in a directory then the file path to the database.
My problem is that now i`m trying to use the script in the website server where i uploaded my site files,and its giving me the errors as below:
Warning: move_uploaded_file() [function.move-uploaded-file]: failed to open stream: FTP server reports 530 Login authentication failed in /home/kislatco/public_html/photo/upload.php on line 16

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTPTywF' to '' in /home/kislatco/public_html/photo/upload.php on line 16

The directory i were using in wampserver(localhost) is
$uploadDir = 'c:/wamp/www/photo/uploads/';
And in the webserver which is giving me errors is


So i dont know what is Wrong?any Help will be apprecited.

Dani AI

Generated

Short summary: the upload failures come from treating the destination as an FTP URL instead of a local filesystem path, and then hitting PHP restrictions when the script tries to write outside allowed folders. That explains the initial FTP login error (an FTP address cannot be used with PHP's file-upload move) and the later open_basedir complaint. As and hinted, the correct approach is to let PHP write to a directory on the same server, and only use FTP APIs when the file must be placed on a different host.

Steps to resolve (in order):

  • Point the upload routine at an actual server filesystem directory that lies inside PHP’s allowed paths. Check the server’s allowed paths with phpinfo() and the open_basedir setting; see the PHP docs on open_basedir for details (open_basedir).
  • Ensure the uploads directory exists and is writable by the webserver process. On shared hosts this is usually done via the control panel or FTP client “File Attributes”; on SSH-enabled systems it requires correct owner/group and write permissions. Avoid leaving a world-writable directory if possible (follow host guidance for minimal safe permissions).
  • If the ultimate destination is a different server, accept the upload locally first and then transfer it using FTP/SFTP or an API rather than passing an ftp:// URL to the upload function; consult the PHP FTP/SFTP docs for secure transfers (FTP extension).

Additional notes: store a public or relative URL in the database instead of an ftp:// path and validate/limit uploaded file types and sizes. The PHP file-upload guide is a concise reference for safe handling (File uploads). These steps address the errors reported by and build on the suggestions already offered by and .

Recommended Answers

All 10 Replies

have you authenticated yourself before using ftp?

"failed to open stream: FTP server reports 530 Login authentication failed"

Do you mean login in ftp?

Why are you trying to use FTP with move_uploaded_file() ?
Are you trying to place the file on a server that is different then the one you are uploading too?

check my code below and tell where i`m getting wrong:

<?php

$uploadDir = '';

if(isset($_POST['upload']))
{
	
	$fileName = $_FILES['userfile']['name'];
	$tmpName = $_FILES['userfile']['tmp_name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];
     
;
	$filePath = $uploadDir . $fileName;

	$result = move_uploaded_file($tmpName, $filePath);
	if (!$result)
	{
	//echo "Error uploading file";
	$filePath="";
	}
		
	if(!get_magic_quotes_gpc())
	{
	$fileName = addslashes($fileName);
	$filePath = addslashes($filePath);
	$fileType = addslashes($fileType);
	} 
	
	
	$dbcnx=@mysql_connect('localhost','****','******');
 if(!$dbcnx){
 exit('<p>unable to connect to the database'.
      ' this time try again later.</p>');
	  }
	  
if (!@mysql_select_db('register')){
	   exit('<p>unable to locate the REGISTER DATABASE'.
	   'AT THIS TIME');
	   }
	
	

	$query = "update picha set path='$filePath',filetype='$fileType',filename='$fileName',date=CURDATE() where user='peacemaker'";//change query according to you
	
	mysql_query($query) or die('Error, query failed');
	$path=$filePath;
	echo "<br>File $fileName uploaded<br>";
	include"index.php";

	
	}
?>

in localhost i used this directory and it was working

<?php
$uploadDir = 'c:/wamp/www/photo/uploads/';
?>

But what are you using FTP for?

if you're on windows: $uploadDir = 'c:/wamp/www/photo/uploads/'; If you're on a windows server still, you should have a similiar path to the directory you want to upload the image too.

if you're on a linux server now, you path with be something like: $uploadDir = '/home/user/public_html/photo/uploads/'; You dont need to use FTP at all. Just make sure the directory you want to upload the image to, exists and is writable.

i changed the directory to

<?php
$uploadDir ='/public_html/photo/uploads/';
?>

And now i`m having the following error,i dont know may be the function move isn`t working


Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/public_html/photo/uploads/Naam012.jpg) is not within the allowed path(s): (/home/kislatco:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in /home/kislatco/public_html/photo/upload.php on line 16

/home/kislatco/public_html/photo/uploads/

make sure the uploads directory is writable.

when you say writable what do u mean,bcoz i`m new in this.
Sorry if i`m asking a lot.

make sure it has write permissions. is you do something like ls -al, it should have a "w" next to your user group.

in FileZilla for example (ftp program) if you log into your site and right click on any folder or file and choose "File Attributes" it will show you the READ/WRITE/EXECUTE permissions for owner, group and public. This is the same as chmod from the command line on the server. Usually i see mention to try 755 first and then move to 777 if it still wont save the image to the folder. But, do not chmod EVERYTHING to 777

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.