...

View Full Version : extremely urgent upload help needed



managedinternet
08-31-2006, 01:53 AM
hi guys

ok below is my code for the page that processes the file upload


$target_path = "../cvstorage/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$cvid = $_GET['cvid'];
$jobseekerid = $_GET['jobseekerid'];
$cvlocation = $_FILES['uploadedfile']['name'];
$keywords = $_GET['keywords'];
mysql_select_db($dbn, $dbc);
$upload = mysql_query("INSERT INTO `cvstorage` (`cvid`,`jobseekerid`,`cvlocation`,`keywords`) VALUES ($cvid,$jobseekerid,'http://www.domain.com/cvstorage/$cvlocation',$keywords)", $dbc);
}
nothing at all happens

im trying to upload a file to the cvstorage folder and then insert the data into the db

please help guys

the site goes live very soon

thanks in advance

sc0ttkclark
08-31-2006, 03:54 AM
sorry, is there a reason you have:



$upload = mysql_query("INSERT INTO `cvstorage` (`cvid`,`jobseekerid`,`cvlocation`,`keywords`) VALUES ($cvid,$jobseekerid,'http://www.domain.com/cvstorage/$cvlocation',$keywords)", $dbc);


instead of:



mysql_query("INSERT INTO `cvstorage` (`cvid`,`jobseekerid`,`cvlocation`,`keywords`) VALUES ($cvid,$jobseekerid,'http://www.domain.com/cvstorage/$cvlocation',$keywords)", $dbc);


about the rest -- i'm not sure about syntax. could use a little simplification maybe?

managedinternet
08-31-2006, 02:29 PM
just copied the query from another page and modified it,

your right though $upload isnt needed


anyone else offer any help, reaching the deadline before the site is going to launch as we have already spend money advertising the 1st as our luanch

thanks

managedinternet
08-31-2006, 07:53 PM
here is teh redone code
still problem happens .. no file uploaded

please , please help guys


$target_path = "http://www.mydomainco.uk/cvstorage/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_file = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);

here is the debugging info

Array ( [file] => Array ( [name] => replicant.ttf [type] => application/octet-stream [tmp_name] => /tmp/php18wJVy [error] => 0 [size] => 42388 ) )

managedinternet
08-31-2006, 09:15 PM
anyone have any ideas at all ?

its very urgent

dsavage666
08-31-2006, 10:04 PM
Here's a working upload script:


<?php

if($image_1)
{
$dir = "media/";
copy($image_1, "$dir"."$image_1_name");
$image_1 = "$dir"."$image_1_name";
echo "File uploaded: $image_1<br>";

//write image name to text file:


$start = "<img src = ";
$finish = "><br>";


$fileopen = fopen("images.htm", "a"); //a stands for append
fputs($fileopen, "$start"); //adds the file name to the open file
fputs($fileopen, "$image_1");
fputs($fileopen, "$finish\n");
fclose($fileopen);
};

echo "<form method=\"post\" action=\"upload.php\"enctype=\"multipart/form-data\">";

echo "Upload Image: <input type=file name=\"image_1\"><br>";

echo "<input type=\"submit\" name=\"upload\" value=\"Add Image\"><p>";

echo "</form>";

?>

This code assumes that this file is uploaded to the server and the appropriate file and directory permissions have been set.

GJay
08-31-2006, 10:25 PM
I think the original code will work if the form uses post rather than get.
I set up:


<?php
if(count($_POST)>0) {
$target_path = "../cvstorage/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$cvid = $_POST['cvid'];
$jobseekerid = $_POST['jobseekerid'];
$cvlocation = $_FILES['uploadedfile']['name'];
$keywords = $_POST['keywords'];
echo "INSERT INTO `cvstorage` (`cvid`,`jobseekerid`,`cvlocation`,`keywords`) VALUES ($cvid,$jobseekerid,'http://www.domain.com/cvstorage/$cvlocation','$keywords')";
}
}
?>

<form action="" enctype="multipart/form-data" method="post">
<input type="file" name="uploadedfile" />
<input type="text" name="jobseekerid" value="12" />
<input type="text" name="keywords" value="some keywords" />
<input type="text" name="cvid" value="7" />
<input type="submit" value="go" />
</form>


and it works fine (I echo the query as I don't have mysql installed, the only change being 's around the keywords)

managedinternet
08-31-2006, 11:13 PM
hi,

thanks guys,

i used GJays ( the same i had )
and it still isnt uploading to the dir or writing to the db

the folder permissions are 777 so im really puzzled

dsavage666
08-31-2006, 11:21 PM
...so the script I posted doesn't work either or are you so caught up with your own code that you can't bother to try someone elses? :confused:

managedinternet
08-31-2006, 11:25 PM
used GJays because i dont understand what i would need to modify in your code, never been too good with fputs etc

managedinternet
09-01-2006, 12:07 AM
guys i fixed it

script was fine ,

i just put the relative path in for teh upload folder ie /home/myuser/public_html/cvstorage/

works fine

thanks to all for thier help

managedinternet
09-01-2006, 12:13 AM
1 thing though.. if the file already exists how do i get it to overwrite the original ?

Mwnciau
09-01-2006, 12:20 AM
$file = '';
if (file_exists($file)){
unlink($file);
}

managedinternet
09-01-2006, 12:32 AM
thanks,

also its not writing to the db

file upload fine though

managedinternet
09-01-2006, 01:18 AM
totally bamboozled

my original script is working however the info is not getting written to the db
:(

ideas anyone ?

GJay
09-01-2006, 07:17 AM
echo the query

managedinternet
09-01-2006, 11:20 AM
hi, GJAY
query is getting echoed without any problems,
seems to be a problem with the connection / query for sor some strange reason
cant put my finger on it at all

GJay
09-01-2006, 11:51 AM
I'll be more specific.
echo the query, and paste it here...

managedinternet
09-01-2006, 01:21 PM
sorry was having a stupid moment & just woke up
ive added print_r($_FILES) as well
to show debugging info for the $Files

INSERT INTO `cvstorage` (`cvid`,`jobseekerid`,`cvlocation`,`keywords`) VALUES (,1,http://www.careerscout.co.uk/cvstorage/CDA.doc,)

Debugging info from print_r($_files);
Array ( [uploadedfile] => Array ( [name] => CDA.doc [type] => application/msword [tmp_name] => /tmp/phpwCEi54 [error] => 0 [size] => 22016 ) )

GJay
09-01-2006, 06:22 PM
want quotes around strings going into the database, and probably something in place of the blanks.

managedinternet
09-01-2006, 07:42 PM
perfect !

GJay.. thanks for your time !
Much appreciated.. really

If you ever want a free hosting account just give me a bell

Cheers again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum