scmeeker Posted February 12, 2012 Share Posted February 12, 2012 Trying to have my image uploader transfer up SWF files without any luck. It uploads the file name correctly but is not transferring the file itself to the file directory. It works fine with my regular images but just not with the SWF files. I've changed all occurences of JPG and replaced them with SWF. Help? Perhaps I'm missing something? Thanks for your help! <?php $item_image = $_FILES['image_upload_box']['name']; $item_id = $_GET['id']; $sql="UPDATE imagetable SET sp_image='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,bmp,x-png and 4 MB max if (($_FILES["image_upload_box"]["type"] == "image/swf" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 400000000)) { // some settings $max_upload_width = 800; $max_upload_height = 300; // if user chosed properly then scale down the image according to user preferances if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){ $max_upload_width = $_REQUEST['max_width_box']; } if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){ $max_upload_height = $_REQUEST['max_height_box']; } // if uploaded image was JPG/JPEG if($_FILES["image_upload_box"]["type"] == "image/swf" || $_FILES["image_upload_box"]["type"] == "image/swf"){ $image_source = imagecreatefromswf($_FILES["image_upload_box"]["name"]); } // if uploaded image was GIF if($_FILES["image_upload_box"]["type"] == "image/gif"){ $image_source = imagecreatefromgif($_FILES["image_upload_box"]["name"]); } // BMP doesn't seem to be supported so remove it form above image type test (reject bmps) // if uploaded image was BMP if($_FILES["image_upload_box"]["type"] == "image/bmp"){ $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["name"]); } // if uploaded image was PNG if($_FILES["image_upload_box"]["type"] == "image/x-png"){ $image_source = imagecreatefrompng($_FILES["image_upload_box"]["name"]); } $remote_file = "image_files/".$_FILES["image_upload_box"]["name"]; imagejpeg($image_source,$remote_file,100); chmod($remote_file,0644); // get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height){ $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefromswf($remote_file); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); } imagedestroy($image_source); MOD EDIT: . . . BBCode tags added. Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317278 Share on other sites More sharing options...
scmeeker Posted February 12, 2012 Author Share Posted February 12, 2012 sorry...they've changed the tagging since I posted last. It used to be above where you type and I looked for it. Sorry! Do you simply put <?php at the beginning of the PHP code and ?> at the end for it to show up properly in the post? Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317293 Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 Select the code block, then click the # button. As long as you have an opening <?php tag in the code block, it will get syntax highlighting at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317294 Share on other sites More sharing options...
scmeeker Posted February 12, 2012 Author Share Posted February 12, 2012 Thanks for that! Did you have a chance to look at the code? I'm so puzzled! I researched and it looked as though I could simply replace the jpeg file name with the SWF file name for the uploader. I don't know if its because it is image/swf...because its actually a movie file which is causing the problem? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317302 Share on other sites More sharing options...
Pikachu2000 Posted February 12, 2012 Share Posted February 12, 2012 My guess is that the check against the permitted file types is failing. Echo $_FILES["image_upload_box"]["type"] and make sure the file type being passed is one of the types being allowed in the conditional. Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317304 Share on other sites More sharing options...
scmeeker Posted February 12, 2012 Author Share Posted February 12, 2012 Okay...I tried it out towards the beginning and the end of the code as $image = $FILES["image_upload_box"]["type"]; Then at the very end I echoed the $image variable but nothing comes up when I test it. Any suggestions at what I'm not doing right? Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317362 Share on other sites More sharing options...
scmeeker Posted February 12, 2012 Author Share Posted February 12, 2012 Do you think the Image Resizer is causing a problem? I also tried setting the SWF as $_FILES["image_upload_box"]["type"] == "media/swf" with no luck. No transfer to the image file. Any suggestions?? Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317371 Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2012 Share Posted February 13, 2012 See what output you get from this after the form has been submitted. Add it at the top of the script. echo '<pre>'; print_r($_FILES); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1317381 Share on other sites More sharing options...
scmeeker Posted February 22, 2012 Author Share Posted February 22, 2012 Thanks SO much for that help. It pushed me in the right direction and I soon found a simple, easy way to upload my swf files with NO problem. I appreciate it!! Quote Link to comment https://forums.phpfreaks.com/topic/256950-swf-uploader-not-working/#findComment-1319828 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.