Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

'waiting for localhost' holdup

Codes here !

Moderators: macek, egami, gesf

'waiting for localhost' holdup

Postby mightyhokie » Tue Jun 19, 2012 5:34 am

My other php pages work perfectly, but when I try and use the upload files code the bottom left of my browser (firefox) says 'waiting for localhost'. I initially wrote the code at work and tested it and it worked no problem but when I took it home (where I do my freelance from) and tried it (after making sure the path was correct, the database was correct, the table and fields had the same name) it just kept lagging and saying 'waiting for localhost'. Once it timed out (i believe..at least it stopped saying 'waiting for localhost') it hadn't written to the database nor placed the images in the correct folder (or any folder). The php.ini file says the upload permissions are on, and that the size limit is 50M so that def is not the problem.

Below is the code I used.

Form
Code: Select all
<form action="adminList.php" name="form" method="POST" enctype="multipart/form-data">

                                      <input type="file" name="files[]" multiple />
                                      <input type="submit" value="Upload" />
                                      <input type="hidden" name="MM_insert" value="form">
                            </form>


PHP
Code: Select all

<?php require_once('Connections/dottieann.php'); ?>
<?php

$imgPath = "img/photos/listings/";

if(isset($_FILES['files'])){
      foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){
         move_uploaded_file($tmp_name, "$imgPath{$_FILES['files']['name'][$key]}");
         $path = ($_FILES['files']['name'][$key]);
         $sqlst = ("INSERT INTO img (files) VALUES (".$path.")");
         print_r($sqlst."<br>");
         
         mysql_query(sprintf("INSERT INTO img (files) VALUES ('".$path."')"));
         }
      }
?>


and a screenshot of my table
Untitled-1.jpg
Untitled-1.jpg (165.81 KiB) Viewed 300 times


I HAVE to be done with this project in the next couple of days or I lose the clients and I've already put 80+ hours into it. Please help this noob get around this problem!
Thanks!
mightyhokie
New php-forum User
New php-forum User
 
Posts: 6
Joined: Fri Jun 01, 2012 2:51 pm

Re: 'waiting for localhost' holdup

Postby johnj » Tue Jun 19, 2012 8:41 am

1).Try an example

if the above works

2). put echo "line a"; or some identification just after each line in your file and see upto which line the control goes and gets stuck.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: 'waiting for localhost' holdup

Postby egami » Tue Jun 19, 2012 8:50 am

on AdminList.php add the following lines..


if (isset($_FILES)) {
echo '<pre>'; print_r($_FILES); echo '</pre>';
}

If you see that the files in the result, they will have been uploaded to the $TMP directory.. ($TMP being defined as your system temporary directory.) (Since this is WINDBLOWS.. you're on your own for this one..)

The next thing I would do is set a trap. Remember to ALWAYS set traps.

IF you have an IF statement, YOU should have a CLOSING statement too.

if (isset($thisVariable)) {
do this...
}

Well.. ok.. IF $thisVariable is set, do it, otherwise.. don't tell me anything..
========THIS IS THE WRONG APPROACH =======================


if (isset($thisVariable)) {
do this..
} else {
Tell me why it went wrong...
}


ie..
Code: Select all

if 
(isset($_FILES['file'])) { 
  if 
(is_uploaded_file($_FILES['file']['0']['tmp_name'])) { 
  
/* NOTICE: The system will give this file a temp name in the $TMP directory, nothing of which looks like the original file name.. and is deleted upon script execution completion. */
  
  
// BUT YOUR MISTAKE IS HERE... 
  foreach($_FILES['files']['tmp_name'] as $key => $tmp_name) { 
  
// Take a look at your FORM code. You'll notice that the name of your "file" is "file[]"
  // This automagically makes this array look like...
  // $_FILES['files']['0']['tmp_name'] for the first file..
  // $_FILES['files']['1']['tmp_name'] for the second.. and so on.. 
  // So $_FILES['file']['tmp_name'] doesn't exist. This is where your script chokes and dies.. miserably.

  // Change your script to this..
  foreach($_FILES['files'] as $key => $array) { 
     $success
[$array['name']] = move_uploaded_file($array['tmp_name'], "$imgPath".$_FILES['files'][$key]['name']);
     //... your other misc stuff... 
  }
}
 else { 
  echo 
"Woops! Something went horribly wrong. Check the LOG FILE for problems.";
}
 
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron