Jump to content

Image Upload Problem


squire2k

Recommended Posts

Hi I have recently created an image uploader, and works absolutely fine from as many browsers and setups as i can find. However when my client tries to use it, it doesnt work :-( the path to the image is working fine, but the image itself doesnt upload. I'm wondering if anything could be restricting the upload such as anti virus/firewall etc

 

here is my insert.php code

 

<?php

session_start();

 

if (!isset($_SESSION['basic_is_logged_in'])

    || $_SESSION['basic_is_logged_in'] !== true) {

 

    header('Location: index.php');

    exit;

}

 

?>

 

 

<?php

$con = mysql_connect("localhost","lhh","23poi");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("lhh", $con);

 

$shortdescription = mysql_escape_string($_POST['shortdescription']);

$longdescription = mysql_escape_string($_POST['longdescription']);

$propertyname = mysql_escape_string($_POST['propertyname']);

 

$sql="INSERT INTO properties (propertyname, price, location, shortdescription, longdescription, userfile)

VALUES

('$propertyname','$_POST[price]','$_POST[location]','$shortdescription','$longdescription','$userfile_name' )";

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "Property Added<br /><br /><a href='properties.php'>Back to Properties</a><br /><br />";

 

if ($userfile_size >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";

$file_upload="false";}

 

if (!($userfile_type =="image/jpeg" OR $userfile_type=="image/gif" OR $userfile_type=="image/jpg")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";

$file_upload="false";}

 

$add="upload/$userfile_name"; // the path with the file name where the file will be stored, upload is the directory name.

 

if(move_uploaded_file ($userfile, $add)){

// do your coding here to give a thanks message or any other thing.

}else{echo "However, it looks like you didn't add an image, you may wish to add this property again an include a picture!.";}

 

 

 

any ideas would be gratefully received! :-) thanks in advance

Link to comment
Share on other sites

hi thanks for your interest in my problem, the $userfile is being passed from the add form before hand on a previous page, here is my code:

 

 

<form action="insert.php" method="post" enctype="multipart/form-data">

<table width="400" border="0" cellspacing="1" cellpadding="2">

<tr>

<td width="100">Property Name</td>

<td><input name="propertyname" type="text" id="propertyname"></td>

</tr>

<tr>

<td width="100">Price</td>

<td><input name="price" type="text" id="price"></td>

</tr>

<tr>

<td width="100">Location</td>

<td><input name="location" type="text" id="location"></td>

</tr>

<tr>

<td width="100">Short Description</td>

<td><textarea name="shortdescription" type="text" rows="5" id="shortdescription" cols="60"></textarea></td>

</tr>

<tr>

<td width="100">Long Description</td>

<td><textarea name="longdescription" rows="10" id="longdescription" cols="60"></textarea></td>

</tr>

<tr>

<td style="white-space:nowrap;">Image (333px wide x 250px high)</td>

<td><input name="userfile" type="file"></td>

</tr>

<tr>

<td width="100"> </td>

<td> </td>

</tr>

<tr>

<td width="100"> </td>

<td><input type="submit" value="Add New Property"></td>

</tr>

</table>

</form>

 

 

i hope that helps, also yes i can confirm i have used there exact files and work fine from my test setups...so wierd? it's saving the path to the DB OK, just not moving the file up onto the server

 

Link to comment
Share on other sites

Firstly, that code is dependent on register globals. If this works on your server but not theirs, this is probably the reason why. Even if register globals are not the problem, rewrite the code so that it is not dependent on register globals (register globals have been completely removed in php6, so if you want your code to continue working under php6, fix it now or you will need to spend more time later fixing it when it stops working under php6.)

 

Secondly, there is no error checking to see if the upload worked before access any of the uploaded file information. You need to check the ['error'] element. See this link - www.php.net/manual/en/features.file-upload.errors.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.