View Full Version : Problem uploading images

10-24-2003, 01:15 PM
I have a PHP script to upload images via a form to the server that worked before WestHost 2 was implemented, but doesn't work now. Nothing happens; the page just sits there and my mouse cursor stays on "hourglass" until I hit stop on the browser.

Any thoughts?

10-27-2003, 11:17 AM
Can't really say without seeing the code of the script (or if you are using one downloaded off the net, a URL for it). It may be that your paths are wrong, or an error in your code. It could also be that the file you are trying to upload is pretty big, the WestHost servers are slow and it is taking longer than you wish to wait. If this is a PHP upload script, check your /tmp folder to see if you have some phpxxxxxx files (where xxxxxx is a random mixed-case string) - what that means is that it is the latter case, that the file upload is just really slow and you aren't waiting long enough.

10-27-2003, 12:21 PM
The files aren't very big, and I checked the /tmp directory with no success. Anyways, here's the code I'm using:

if ($imgURL) {
echo "We have an image.";
if ($imgURL_size == 0) { exit("Error: uploaded file size is zero.");}
if (!getimagesize($imgURL)){ exit("Error: uploaded file is not an image.");}
if (!is_uploaded_file($imgURL)){ exit("Error: possible file upload attack.");}
$imgURLFile = "/images/news/".$imgURL_name;
if (!copy($imgURL, $imgURLFile)) { exit("Error: could not move file into directory"); }
chmod ($imgURLFile, 0644);
} else { echo "No image file selected.<br /><br />\n"; }

It never gets to

echo "We have an image.";

It just sits there on the form page, with the hourglass on the cursor and the statusbar saying Waiting for www.calgarysaracens.com. Here's the image part of the form:

<input type="file" name="imgURL" size="30">

10-27-2003, 12:26 PM
Alright, I tried using a different browser and it worked fine. Any ideas why the code would work in IE and not in Mozilla?

10-27-2003, 01:06 PM
Weird. What does the HTML for the form look like? I use Mozilla as well and can test it for you if you like.

10-27-2003, 03:38 PM
It's behind a password, but the form HTML looks like this:

<form method="post" action="news.php" enctype="multipart/form-data">
<fieldset align="center"><legend>News Item</legend>
<table class="main" align="center">
<td>Date (MM DD YYYY):</td>
<select size="1" name="month" class="date">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
<select size="1" name="day" class="date">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="22">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<select size="1" name="year" class="date">
<option value="2002">2002</option>
<option value="2003">2003</option>
<td>Image URL:</td>
<td><input type="file" name="imgURL" size="30"></td>
<td colspan="3"><input type="text" class="text" name="author" size="50"></td>
<td colspan="3"><input type="text" class="text" name="title" size="50"></td>
<td valign="top">Prologue:</td>
<td colspan="3"><textarea cols="60" rows="5" name="prologue" class="text"></textarea></td>
<td valign="top">Article:</td>
<td colspan="3"><textarea cols="60" rows="20" name="article" class="text"></textarea></td>
<br />
<fieldset align="center"><legend>Submit</legend>
<input type="submit" value="Submit" class="date">
<input type="button" value="Cancel" class="date" onClick="javascript:parent.location.href='.././index.php';">

10-28-2003, 06:25 AM
That looks fine too :( If this is a browser issue, then it is definitely a problem in your HTML code (or a problem/bug with the browser), and not your server-side code (i.e. PHP).

Try the following code (more or less taken out of the PHP manual) to see if it works or not:

<? if (!$_POST['submit']) { ?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedfile">
<input type="submit" name="submit" value="upload">

<? } else {
echo 'File upload complete<br>';
echo 'File name: '.$_FILES['uploadedfile']['name'].'<br>';
echo 'File size: '.$_FILES['uploadedfile']['size'].'<br>';

if (move_uploaded_file($_FILES['uploadedfile']['tmp_n ame'], $_FILES['uploadedfile']['name'])) echo "<a
href=\"/".$_FILES['uploadedfile']['name'].">Click to view</a>";
else echo "Oops, an error occurred when trying to move the file!";
} ?>