image uplaod code does not want to work on live server.


I have created a basic image upload for a content management system and I have used this format on a few different sites and made them live without any issue.

The problem I have now come across is this, the code I use works on my testing server and other hosting servers but on the one my client has all information is uploaded to the database fine but the actual image file is not being upplaoded to the directory.

The only difference I can see with the hosting is that this is running PHP 5.2.13 and my testing server is running 5.2.9-2. I have included the basic code below if anyone can shed any light on this I would be eternally gratefull as it is driving me insane!

$editFormAction = $_SERVER[‘PHP_SELF’];
if (isset($_SERVER[‘QUERY_STRING’])) {
$editFormAction .= “?” . htmlentities($_SERVER[‘QUERY_STRING’]);

if ((isset($_POST[“MM_insert”])) && ($_POST[“MM_insert”] == “form1”)) {
$insertSQL = sprintf(“INSERT INTO projects (header, copy, image) VALUES (%s, %s, %s)”,
GetSQLValueString($_POST[‘header’], “text”),
GetSQLValueString($_POST[‘copy’], “text”),
GetSQLValueString($_FILES[‘image’][‘name’], “text”));

mysql_select_db($database_standard, $standard);
$Result1 = mysql_query($insertSQL, $standard) or die(mysql_error());

$insertGoTo = "list_projects.php";

if (isset($_SERVER[‘QUERY_STRING’])) {
$insertGoTo .= (strpos($insertGoTo, ‘?’)) ? “&” : “?”;
$insertGoTo .= $_SERVER[‘QUERY_STRING’];
header(sprintf(“Location: %s”, $insertGoTo));
if (array_key_exists(‘upload’, $_POST)) {
// define constant for upload folder
define(‘UPLOAD_DIR’, ‘gal_img/’);
// move the file to the upload folder and rename it
move_uploaded_file($_FILES[‘image’][‘tmp_name’], UPLOAD_DIR.$_FILES[‘image’][‘name’]);

I am not sure what is the problem, but you can try this comparison:

instead of this:
[php]if(array_key_exists(‘upload’, $_POST)){[/php]

Thanks, but it just created:

Parse error: parse error in C:\htdocs\heyrod_contruction\add_project.php on line 128

the array key links in with the form, the problem is it all works but not on my client server and I cant figure out why?

thanks anyway.

ops, missed closing ) Here is corrected line:

Also, looks like your dev environment is Win? Probably you just need to set writting permission on folders where you write files (on Unix).

thanks again,

that gave me undefined index, I do develop on Windows but this normally runs smoothly on the other linux hosting I have used, not really got any experience with Unix at all.

Thanks for the Help!

I have managed to sort this now, it turens out it was permissions on the directory the images as being sent to.

Ross. :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service