peter_anderson Posted October 12, 2009 Share Posted October 12, 2009 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'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 More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 Instead of $filename = $_FILES['uploadfile']; use $filename = $_FILES['uploadfile']['tmp_name']; and instead of $extension = end(explode('.', $filename)); try $extension = pathinfo($filename,PATHINFO_EXTENSION); Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935410 Share on other sites More sharing options...
peter_anderson Posted October 12, 2009 Author Share Posted October 12, 2009 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'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 Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935416 Share on other sites More sharing options...
Mark Baker Posted October 12, 2009 Share Posted October 12, 2009 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 Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935426 Share on other sites More sharing options...
peter_anderson Posted October 12, 2009 Author Share Posted October 12, 2009 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 Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935581 Share on other sites More sharing options...
peter_anderson Posted October 12, 2009 Author Share Posted October 12, 2009 Sorry to bump the thread, but can anyone help? The directory is full permission. Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935650 Share on other sites More sharing options...
lemmin Posted October 12, 2009 Share Posted October 12, 2009 Those $_POST and $_FILE variables aren't set. Make sure you are actually submitting the form when you get those errors. Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935659 Share on other sites More sharing options...
peter_anderson Posted October 12, 2009 Author Share Posted October 12, 2009 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. Link to comment https://forums.phpfreaks.com/topic/177407-array-to-string-conversion/#findComment-935698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.