LuciBKen Posted June 19, 2007 Share Posted June 19, 2007 Hey everyone, I have a script that is supposed to upload files to a folder on my webserver, and also write the info to a mysql table, it also writes the info to a csv file, now, here's what it does, it writes the data to the database, but doesn't upload the files, and doesn't write to the csv. Here's my code for anyone who would like to take a look: <?php // Receiving variables @$pfw_ip= $_SERVER['REMOTE_ADDR']; @$textfield = addslashes($_POST['textfield']); @$textarea = addslashes($_POST['textarea']); @$file_Name = $_FILES['file']['name']; @$file_Size = $_FILES['file']['size']; @$file_Temp = $_FILES['file']['tmp_name']; @$file_Mime_Type = $_FILES['file']['type']; @$file2_Name = $_FILES['file2']['name']; @$file2_Size = $_FILES['file2']['size']; @$file2_Temp = $_FILES['file2']['tmp_name']; @$file2_Mime_Type = $_FILES['file2']['type']; function RecursiveMkdir($path) { if (!file_exists($path)) { RecursiveMkdir(dirname($path)); mkdir($path, 0777); } } // Validation if (strlen($textfield) == 0 ) { die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter the title of the video</font></p>"); } if (strlen($textarea) == 0 ) { die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a description</font></p>"); } if( $file_Size == 0) { die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } if( $file_Size >512000000) { //delete file unlink($file_Temp); die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } if( $file_Mime_Type != "application/x-shockwave-flash" ) { unlink($file_Temp); die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } $uploadFile = $file_Name ; if (!is_dir(dirname($uploadFile))) { @RecursiveMkdir(dirname($uploadFile)); } else { @chmod(dirname($uploadFile), 0777); } @move_uploaded_file( $file_Temp , $uploadFile); chmod($uploadFile, 0644); $file_URL = "http://www.mysite.com/path/to/files/".$file_Name ; if (strlen($file) == 0 ) { die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } if( $file2_Size == 0) { die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } if( $file2_Size >1024000) { //delete file unlink($file2_Temp); die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } if( $file2_Mime_Type != "image/jpeg" ) { unlink($file2_Temp); die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } $uploadFile = $file2_Name ; if (!is_dir(dirname($uploadFile))) { @RecursiveMkdir(dirname($uploadFile)); } else { @chmod(dirname($uploadFile), 0777); } @move_uploaded_file( $file2_Temp , $uploadFile); chmod($uploadFile, 0644); $file2_URL = "http://www.mysite.com/path/to/files/".$file2_Name ; if (strlen($file2) == 0 ) { die("<p align='center'><font face='Arial' size='2' color='#000000'>Please enter a file path</font></p>"); } //saving record in a text file $pfw_file_name = "videolist.csv"; $pfw_first_raw = "textfield,textarea,file,file2\r\n"; $pfw_values = "$textfield,".str_replace ("\r\n","<BR>",$textarea ).",$file_Name,$file2_Name\r\n"; $pfw_is_first_row = false; if(!file_exists($pfw_file_name)) { $pfw_is_first_row = true ; } if (!$pfw_handle = fopen($pfw_file_name, 'a+')) { die("Cannot open file ($pfw_file_name)"); exit; } if ($pfw_is_first_row) { if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } } if (fwrite($pfw_handle, $pfw_values) === FALSE) { die("Cannot write to file ($pfw_filename)"); exit; } fclose($pfw_handle); //saving record to MySQL database @$pfw_strQuery = "INSERT INTO `jos_video_player`(`title`,`description`,`file`,`thumbnail`)VALUES (\"$textfield\",\"$textarea\",\"$file_Name\",\"$file2_Name\")" ; @$pfw_host = "*********"; @$pfw_user = "*****"; @$pfw_pw = "*******"; @$pfw_db = "********"; $pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw); if (!$pfw_link) { die('Could not connect: ' . mysql_error()); } $pfw_db_selected = mysql_select_db($pfw_db, $pfw_link); if (!$pfw_db_selected) { die ('Can not use $pfw_db : ' . mysql_error()); } //insert new record $pfw_result = mysql_query($pfw_strQuery); if (!$pfw_result) { die('Invalid query: ' . mysql_error()); } mysql_close($pfw_link); echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Your upload was a success!</font></p>"); ?> I'd love it if anyone could help, it's probably something small I would guess?!? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/ Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 why do you have put all those @ @move_uploaded_file( $file_Temp , $uploadFile); im not sure but i think the error is that $uploadFile this should be a folder directory where to place those file Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277223 Share on other sites More sharing options...
LuciBKen Posted June 19, 2007 Author Share Posted June 19, 2007 To ease my pain and crank out some scripts that are on-the-fly, I use a form builder, it inserts all of the '@'s. As far as the code you speak of, I will check the docs, but I believe that a variable was set previously for that function. I'll check into it. Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277225 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 heres how to debug echo those data that might causing trouble like the directory or hard code the directory you are putting those file move_uploaded_file( $file_Temp , 'your folder/'. temp name ); Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277226 Share on other sites More sharing options...
LuciBKen Posted June 19, 2007 Author Share Posted June 19, 2007 Still nothing ... It runs through the whole dang script, but it just won't upload that file. I have also made sure that allowing http uploads is enabled in my php.ini file. I'm not sure what else to try. Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277232 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> compare it works fine !! Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277234 Share on other sites More sharing options...
LuciBKen Posted June 19, 2007 Author Share Posted June 19, 2007 I just noticed that you got that example from w3schools.com, which is fine, but a closer look at my code shows that I am trying to upload two files at once. This is an upload from a form, and the file directory is defined in the code. I'm not sure that the result is going to be any different regardless of the little snippet that I use. If you disagree, let me know, and why? Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277245 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 I give that simple script to give you idea but looks like your not a beginner so i guess i should say remove those @ and tell me the errors Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277246 Share on other sites More sharing options...
LuciBKen Posted June 19, 2007 Author Share Posted June 19, 2007 Well, I have no problem admitting that I was wrong ... and I was. When I removed the '@'s the thing worked beautifully. Thank you! Thank you! Thank you! I am definitely in your debt, I have been trying to get this piece of S**t running for two days, and I have no hair left on my head. Thanks a million teng84! Quote Link to comment https://forums.phpfreaks.com/topic/56125-solved-having-trouble-with-a-script-that-is-supposed-to-upload-files/#findComment-277253 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.