squire2k Posted February 6, 2008 Share Posted February 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
affordit Posted February 6, 2008 Share Posted February 6, 2008 Where is $userfile_name being defined Quote Link to comment Share on other sites More sharing options...
schilly Posted February 6, 2008 Share Posted February 6, 2008 did you try the file their using? Quote Link to comment Share on other sites More sharing options...
squire2k Posted February 11, 2008 Author Share Posted February 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2008 Share Posted February 11, 2008 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 Quote Link to comment Share on other sites More sharing options...
squire2k Posted February 11, 2008 Author Share Posted February 11, 2008 thanks for your help - im not sure what register globals are but will look in to that to make it future proof - however, the code is accessed from the same server all the time from different places, some of which work, others that dont. ??? Quote Link to comment Share on other sites More sharing options...
schilly Posted February 11, 2008 Share Posted February 11, 2008 are they able to upload a different file? I've had upload problems be file specific. Quote Link to comment Share on other sites More sharing options...
squire2k Posted February 11, 2008 Author Share Posted February 11, 2008 nope, and theyve sent me the failing files and i can do them fine - it wouldn't be anything to do with the CHMOD thingies would it... can you tell i'm new to php lol? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2008 Share Posted February 11, 2008 What are the symptoms? Which message is output by the code? Quote Link to comment Share on other sites More sharing options...
squire2k Posted February 11, 2008 Author Share Posted February 11, 2008 there isnt one :-( i realise there is no error checking, but wondered if there was anything instantly obvious going on... Quote Link to comment Share on other sites More sharing options...
schilly Posted February 11, 2008 Share Posted February 11, 2008 Well if it's working for you then you know it works. It could be a browser/OS issue. Do you have the resources to reproduce the environment? Or put debug statements in and have it echo out then have the client sent you what it says. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.