wrathican Posted July 5, 2007 Share Posted July 5, 2007 the code below is meant to determine whether or not a file has been set to transfer the problem i have is that it doesnt upload the file it returns me back to the form... so that tells me that the file isnt gettin sent can someone have a look and suggest any help? thanks in advanced <?php //addalbum.php included into galleryadmin.php //if $_POST is set then upload file and add data to DB //else show the form to add a new album if (isset($_POST['image']) && $_POST['image']['size'] <= 0) { //upload file and add to db $fileName = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $description = $_POST['description']; $albumname = $_POST['title']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = '..images/gallery/' . $randName . '.' . $ext; $result = move_uploaded_file($tmpName, $filePath); if(!$result){ echo "Error uploading file"; exit; } $imagepath = $randName . '.' . $ext; if(!get_magic_quotes_gpc()) { $albumname = addslashes($albumname); $imagepath = addslashes($imagepath); $description = addslashes($description); } $query = "INSERT INTO cy_album (al_name, al_description, al_image ) ". "VALUES ('$albumname', '$description', '$imagepath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); echo $query; }else{ //show form ?> <form action="galleryadmin.php?func=addalbum" method="post" enctype="multipart/form-data" name="form1"> <p>Album Title:<br> <input type="title" name="textfield"> <br> Description: <br> <textarea name="description" cols="50" rows="7"></textarea> <br> Image: <br> <input name="image" type="file" id="image"> <input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="2000000"> <br> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"> <br> <a href="galleryadmin.php">Back</a></p> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 5, 2007 Author Share Posted July 5, 2007 i guess nobody has any idea then..? Quote Link to comment Share on other sites More sharing options...
john010117 Posted July 5, 2007 Share Posted July 5, 2007 Your $filePath = '..images/gallery/' . $randName . '.' . $ext; is not valid. Try $filePath = '../images/gallery/' . $randName . '.' . $ext; Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 5, 2007 Author Share Posted July 5, 2007 hmm this didnt help.. thanks for the reply though Quote Link to comment Share on other sites More sharing options...
john010117 Posted July 5, 2007 Share Posted July 5, 2007 Where exactly is your /images/gallery directory relative to the file with your script? Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 5, 2007 Author Share Posted July 5, 2007 my folder layout: root -cms --this is where my file is -images Quote Link to comment Share on other sites More sharing options...
john010117 Posted July 5, 2007 Share Posted July 5, 2007 Make the change I showed you, then put the form at the top of the script <?php error_reporting(E_ALL); if(!isset($_POST['Submit'])) { // Form goes here } else { // Upload script goes here // Then the MySQL stuff goes here } ?> Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 5, 2007 Author Share Posted July 5, 2007 thanks for the help got it sorted now 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.