Jump to content

Array to string conversion


peter_anderson

Recommended Posts

Can anyone help me with this?

 

Notice: Array to string conversion in /home/..../index.php on line 360

 

Whatever this is, it's causing the script to fail at uploading.

 

Code (starting just before line 360)

<?php

//snip
$ipadd = $_POST['ipadd'];
	$filename = $_FILES['uploadfile'];
	$save_path = $config['uploaddir'];
	$extension = end(explode('.', $filename)); #extension of the file #LINE 360
	$fid = rand(1690, 16901690);
	$renamed = md5($filename. time()); #rename of the file
	if (!@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $save_path.$renamed. $extension)) {
	/*if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target_path)) {*/
		$username = $_SESSION['username'];
		$filel = "$save_path.$renamed. $extension.";
		$query = "INSERT INTO `files`(owner, filelocation, ipadd, fid)
		 VALUES('$username', '$filel', '$ipadd', '$fid')";
		$result = $sql->query($query);
		$content = '<h1>The file has been uploaded!</h1>
			<h2>You may download it <a href="?action=downloadFile&file='.$fid.'" target="_blank">here.</a></h2>
			<p>Thank you for uploading the file to our file sharing service.</p>
			<p>It has now been uploaded and is ready for downloads.</p>
			<p>Copy and paste this link for distributing the file.</p>
			<p>http://www.'.$_SERVER['SERVER_NAME'].'/?action=downloadFile&file='.$fid.'</p>';
		//echo "The file ".  basename( $_FILES['uploadfile']['name'])." has been uploaded";
	} else{
		$content = '<h1>File Upload Error</h1>
			<h2>Oops, the file couldn&#39;t be uploaded!</h2>
			<p>The file you tried to upload has NOT been uploaded.</p>
			<p>This could be because:<br />
			- the file is already on the server<br />
			- the server is full<br />
			- the file was named the same as an already existing file<br />
			- the server is not accepting new uploads.</p>
			<p>Please contact our support team or the webmaster.</p>';
	}
?>

 

Thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/
Share on other sites

Instead of

$filename = $_FILES['uploadfile'];

use

$filename = $_FILES['uploadfile']['tmp_name'];

 

and instead of

$extension = end(explode('.', $filename));

try

$extension = pathinfo($filename,PATHINFO_EXTENSION);

 

Thanks :)

 

That got rid of the error :)

 

Now, it isn't uploading, though. It shows the error I message I have (

<h1>File Upload Error</h1>
			<h2>Oops, the file couldn&#39;t be uploaded!</h2>
			<p>The file you tried to upload has NOT been uploaded.</p>
			<p>This could be because:<br />
			- the file is already on the server<br />
			- the server is full<br />
			- the file was named the same as an already existing file<br />
			- the server is not accepting new uploads.</p>
			<p>Please contact our support team or the webmaster.</p>

)

 

I've got error reporting on, but its not giving any errors.

 

Any ideas?

 

Thanks

I've got error reporting on, but its not giving any errors.

The @ sign suppresses errors:

if (!@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $save_path.$renamed. $extension)) {

 

Remove that, and see if you get any errors displayed

I've got error reporting on, but its not giving any errors.

The @ sign suppresses errors:

if (!@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $save_path.$renamed. $extension)) {

 

Remove that, and see if you get any errors displayed

 

Ok, I now get

 

Notice:  Undefined index:  ipadd in .... on line 357

Notice:  Undefined index:  uploadfile in .... on line 358

 

Which I guess means it isn't receiving the data?

 

Here's my submit form:

 

<?php

//snip
<form action="?action=uploadProcess" enctype="multipart/form-data" method="post" name="uploadForm">
			<p><input id="upload" style="width:80%;" name="uploadfile" type="file" />
			<input type="hidden" name="username" value="'.$_SESSION['username'].'" />
			<input type="hidden" name="ipadd" value="'.$_SERVER["REMOTE_ADDR"].'" />
			<input id="upload" name="upload" type="submit" value="Upload Now!" /></p>
			</form>
?>

 

File uploading is complicated :)

Those $_POST and $_FILE variables aren't set. Make sure you are actually submitting the form when you get those errors.

 

The file is created in the directory using a random name, but without the extension.

 

Echo'ing the filename and extension shows "Array" for file name and nothing for extensino.

 

I am submitting the form using the code I posted earlier.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.